(编辑:jimmy 日期: 2024/10/11 浏览:2)
x==y returns true
x===y returns false
(x < 10 && y > 1) returns true
|| or(x==5 || y==5) returns false
! not!(x==y) returns true
A string is most often text, for example "Hello World!". To stick two or more string variables together, use the + operator.
在文字当中使用的比较多,举例来说“Hello World!”要将两个或多个字符串变量衔接在一起的话就得使用 + 符号
txt1="What a very" txt2="nice day!" txt3=txt1+txt2
The variable txt3 now contains "What a verynice day!".
txt3变量现在包含“What a verynice day!”(把1和2衔接起来了)
To add a space between two string variables, insert a space into the expression, OR in one of the strings.
要给两个字符串变量中间添加空格就得在表达式里插入空格,或在其中的一个加上(空格)
txt1="What a very" txt2="nice day!" txt3=txt1+" "+txt2
or
txt1="What a very " txt2="nice day!" txt3=txt1+txt2
The variable txt3 now contains "What a very nice day!".
现在变量txt3为“What a very nice day!”
JavaScript also contains a conditional operator that assigns a value to a variable based on some condition.
JS有根据条件不同给变量不同值的条件运算符
variablename=(condition)?value1:value2
greeting=(visitor=="PRES")?"Dear President ":"Dear "
If the variable visitor is equal to PRES, then put the string "Dear President " in the variable named greeting. If the variable visitor is not equal to PRES, then put the string "Dear " into the variable named greeting.
如果变量visitor的值等于PRES那么greeting的值就为"Dear President "。如果不为PRES那么greeting的值就为"Dear"