Linked Questions

122 questions linked to/from Javascript function scoping and hoisting
89 votes
5 answers
12k views

I came across JavaScript 'hoisting' and I didn't figure out how this snippet of code really functions: var a = 1; function b() { a = 10; return; function a() {} } b(); alert(a); I know ...
morfioce's user avatar
  • 1,117
29 votes
3 answers
3k views

I was reading about JavaScript scopes and Hoisting. I saw a sample as below that made some doubts on my mind. So, I was wondering how it works. var a = 1; function b() { a = 10; return; ...
4 votes
6 answers
3k views

Hi I am trying to understand the JavaScript fundamentals, and stuck in one condition. var foo = 1; function bar(){ foo = 10; return; function foo(){} } ...
pradeepks's user avatar
8 votes
4 answers
3k views

I have a Javascript code as below, http://jsfiddle.net/ramchiranjeevi/63uML/ var foo = 1; function bar() { foo = 10; return; function foo() {} } bar(); console.log(foo); // returns 1 ...
Jeevi's user avatar
  • 1,052
3 votes
3 answers
1k views

I was reading this article and I have some questions please: considering this code : 1: var a = 1; 2: function b () { 3: a = 10; 4: return; 5: function a() {} 6: } 7: b();...
10 votes
1 answer
346 views

Can anybody break down for me into steps how this (it looks simple in the first place) is interpreted by the browser: var a = 1; function b() { a = 10; function a() {} } b(); alert(a); it ...
funguy's user avatar
  • 2,160
0 votes
2 answers
2k views

Why is this global variable undefined inside a function if the same global variable is re-declared and defined inside that same function? var a = 1; function testscope(){ console.log(a, 'inside ...
Raj Rj's user avatar
  • 3,587
1 vote
2 answers
155 views

var x = 2; function fun() { x = 3; var x = 4; document.write(x); } document.write(x); fun() document.write(x); Can someone help me understand the flow of control. Why is the ...
1 vote
1 answer
143 views

I called helloworld and defined it with below two different ways: 1) With variable 2) With function name itseld var helloWorld = function() { return '2'; } function helloWorld() { return '...
0 votes
1 answer
1k views

What is the difference between the following two cases: CASE 1: console.log(c); //console : undefined var c; CASE 2: console.log(c); //console : Uncaught ReferenceError: c is not defined Why in ...
3 votes
2 answers
133 views

In an interview, I was asked to guess the output of the following snippet: var foo = 1; function bar() { foo = 10; return; function foo() { } } bar(); console.log(foo); ...
Ramesh Reddy's user avatar
  • 10.7k
0 votes
5 answers
100 views

Is the var highScore = 0 apart of the loop? Isn't scores[i] always greater than 0? I need someone to break down how the if statement is working, and I need to understand how highScore = scores[i] is ...
tkss44's user avatar
  • 33
-2 votes
2 answers
867 views

Since constructors are basically an object that is stored as a copy, it seems like they are treated like a variable in the sense that they cannot be just "Anywhere" in the code, like with a function ...
0 votes
1 answer
409 views

Using older syntax Prints "this is myfunc1" myfunc1(); function myfunc1() { console.log("this is myfunc1"); } Using es6 syntax This gives error "myfunc2 is not a function" myfunc2(); var myfunc2 =...
1 vote
2 answers
88 views

I am kind of novice in JavaScript, I really don't quite understand why the below code return 1 instead of 10: var a = 1; function b() { a = 10; return; function a() {} } b(); alert(a); ...
cuongle's user avatar
  • 75.5k

15 30 50 per page
1
2 3 4 5
...
9