Puzzle One:
First look at the example:
function test () {message = "HI";} Test (); alert (message);
Will output the string "HI"
Variables defined using var inside a function are local variables, and variables that omit the var operator are global variables.
Puzzle Two:
alert (undefined = = null)
The result is "true"
We know that in JS there are basic types and reference types, and the base type contains number, String, Boolean, undefined, null. Assuming that a base type is not initialized, it is a undefined type, and null represents a null pointer.
The undefined value is actually derived from null. Therefore, returns True.
Puzzle Three:
Alert (IsNaN (NaN)); Truealert (IsNaN (Ten)); Falsealert (IsNaN ("ten")); False own Active type conversion alert (IsNaN ("Blue")); Truealert (IsNaN (true)); False self-initiated type conversions
Nan refers to a non-numeric value (not a number) is a special value, in ECMAScript, no matter what the number divided by 0 returns Nan, and no matter what operation that involves Nan will return Nan. Nan is not equal to any value. Contains itself.
Alert (nan = = Nan);
Puzzle Four:
for (var propname in window) {document.write (propname);}
The for-in statement is a precise iterative statement. The properties that can be used to enumerate objects. Similar to for (String s:string[] in Java)
Puzzle Five:
var qs = location.search.substring (1), var hostName = Location.hostname;var url = location.href;//equivalent to the following with (location) { var qs = search.substring (1); var hostName = Hostname;var url = href;}
The function of the WITH statement is to set the scope of the code to a specific object. The main purpose is to simplify the work of writing the same object multiple times.
Puzzle Six:
function Howmanyargs () {alert (arguments.length);} Howmanyargs ("String"); 2howManyArgs (); 0howManyArgs (n); 1
The parameters in the ECMAScript are represented internally by an array. The function always receives this array, regardless of which parameters are included in the array (assuming there are no parameters).
The named parameters are only convenient, but not necessary. Let's look at the following example
function Doadd (NUM1, num2) {arguments[1] = 10;alert (Arguments[0] + num2);}
Because the values in the arguments object are self-reflective to the corresponding named argument, Num2 becomes 10, but their memory space is independent (not a reference), and the length of the arguments object is determined by the number of parameters passed in. is not determined by the number of named parameters when the function is defined.
Puzzle Seven:
for (var i=0; i<10; i++) {}alert (i); Output is 10
JavaScript does not have block-level scopes.
JavaScript you don't know the confusion (1)