1.Re-Declaring JavaScript Variables
-
If you re-declare a JavaScript variable, it will not lose its value.
The variable carName will still have the value "Volvo" after the execution of these statements:
Example
var carName = "Volvo";
var carName;
PS:这个应该是重新定义时没有初始化对应的内存区吧,是编译器和语言的要求吗?!
2.Example
var x = "5" + 2 + 3;
Note:If you add a number to a string, the number will be treated as string, and concatenated.
3.JavaScript evaluates expressions from left to right. Different sequences can produce different results:
---------------------------
JavaScript:
var x = 16 + 4 + "Volvo";
Result:
20Volvo
---------------------
JavaScript:
var x = "Volvo" + 16 + 4;
Result:
Volvo164
[popexizhi:从左到右的啊!
测试了一下
var x =10+4+"Volvo"+20*3;
Result:
14Volvo60
应该是按运算符顺序计算,但遇到字符串后变成字符串运算的。
]
4.typeof
The typeof Operator
You can use the JavaScript typeof operator to find the type of a JavaScript variable:
Example
typeof "John" // Returns string
typeof 3.14 // Returns number
typeof false // Returns boolean
typeof [1,2,3,4] // Returns object
typeof {name:'John', age:34} // Returns object
5.----
Undefined
In JavaScript, a variable without a value, has the value undefined. The typeof is also undefined.
Example
var person; // The value is undefined, the typeof is undefined
没有评论:
发表评论