1. Q: JS "1" +2+ "3" +4 operation results?
Answer:1234
JS, the string and the sum of the values, the result is a string, where the results of 1234 is also a string.
2. Q: What is the result of the 4+3+2+ "1" Operation?
A: the sum (from left to right) is preceded by a value of 9, and then added to the string to get 91 strings. )
3. Q: In the following code, the result is?
var foo = 1; function Bar () { = ten; return ; function foo () {}}bar (); alert (foo);
Answer: will output 1. (Here is the Window.foo, not the Foo inside bar)
4. Q: In the following code, the result is?
function Bar () { return foo; = ten; function foo () {} var foo = one;} Alert (typeof Bar ());
Answer: The function will be output. (var foo = 11 Although the definition is placed behind, but the variable is promoted, so the final result is function)
5. Q: In the following code, the result is?
var x = 3; var foo = { 2, Baz: { 1, function() { returnthis. x;}} } var go = foo.baz.bar;alert (Go ()); alert (Foo.baz.bar ());
Answer:3,1.
Go = Foo.baz.bar; Go () This point is widow. The value of window.x is 3;foo.baz.bar () at this point the value of baz,baz.x is 1.
6. Q: In the following code, the result is?
var x = 4, = { 3, function() { var x = 2; SetTimeout (function() { var x = 1; Alert (this. x); ); } };o Bj.bar ();
Answer: output 4.
The SetTimeout method is hung under the Window object. SetTimeout (anonymous function, time), where the anonymous function forms a closure that allows access to the local variables of the outer function . The X in window. Reference
7. Q: In the following code, the result is?
x = 1; function Bar () { this. x = 2; return x;} var New bar (); alert (foo.x);
Answer: output 2.
Here, this is pointing to the object instance of bar.
8. Q: In the following code, the result is?
function Foo (a) { alert (arguments.length);} Foo (1, 2, 3);
Answer:3.
9. Q: In the following code, the result is?
var function Bar () {}; alert (typeof Bar);
Answer:function (the answer is undefined, I feel wrong, and try to output is also function)
10. Q: In the following code, the result is?
var arr = [];arr[0] = ' a '; arr[1] = ' B '= ' C '; alert (arr.length);
A:2, the value of the output arr is ["A", "B"], not quite understand the results here.
11. Q: In the following code, the result is?
function Foo (a) { arguments[0] = 2; alert (a);} Foo (1);
Answer:2
12. Q: In the following code, the result is?
function foo () {} Delete Foo.length;alert (typeof Foo.length);
Answer:The value of Number;foo.length is 0. Delete cannot be deleted, reference
13. Q: In the following code,
var name= "the window"; var object={
Name:"My Object",
function (){
return this.name;
} }
With the following call
= Object.getname) ()
The result?
For:
The first line of code, this point is the object, so there is no doubt that the second line of code, although the parentheses, it is like just referencing a function, but this is worth maintaining. Because the definitions of object.getname and (Object.getname) are the same. The third line of code executes an assignment statement before invoking the result of the assignment. Because the value of this assignment expression is the function itself, the value of this cannot be maintained and the result is returned to the window.
Front-end Development Question collection (JS section)