Linked Questions

4 votes
1 answer
1k views

hoisting behavior changed between chrome 48 and 49 ? [duplicate]

if (true) { function test() { console.log(true); } } else { function test() { console.log(false); } } test() Chrome 48 (and node <5.9.1) logs false, chrome 49 (and firefox) log ...
rdkn's user avatar
  • 584
3 votes
1 answer
75 views

function expression on firefox - not expected result [duplicate]

if (true) { function foo(){ return 1; } } else { function foo(){ return 2; } } foo(); The above code is an example of function expression and returns 1 in Firefox 28 whereas 2 in Chrome ( expected ...
Vivek Chandra's user avatar
0 votes
0 answers
23 views

What is the definition of "scope" when we are talking about function hoisting in JavaScript [duplicate]

I am learning JavaScript Function Hoisting, which says "the declaration of functions are moved to the top of their scope". Then I read the definition of "scope" from this doc, it ...
Richard Hu's user avatar
71 votes
4 answers
36k views

Are named functions preferred over anonymous functions in JavaScript? [duplicate]

Possible Duplicate: JavaScript: var functionName = function() {} vs function functionName() {} There are two possible methods for pulling out a function in Javascript: var foo = function() { ... }...
Billy ONeal's user avatar
28 votes
2 answers
1k views

How does this hoisting work with block scope? [duplicate]

I've been asked about a question { function foo() { console.log('A'); } foo(); foo = 1; function foo() { console.log('B'); } foo = 2; console.log(foo); } ...
Hao Wu's user avatar
  • 21.6k
6 votes
1 answer
602 views

Firefox: function hoisting error

I used to assume that functions always get hoisted to the top of any block of JavaScript code. For example, this works: document.addEventListener('something', dummy); function dummy(){ console....
mido's user avatar
  • 25.2k
0 votes
3 answers
854 views

//Uncaught Error: Pick color is not a function - I can not find the Error

Everything was fine until I call the function var picked color = pickColor(); I have run the function pickColor() in console separately - works fine!!! Please help!!! Html <!DOCTYPE html> <...
Hossain's user avatar
-1 votes
1 answer
113 views

In javascript, what are the "statement positions"? [closed]

I read in this article that function declarations can appear only in statement position. I'm wondering what are these "statement positions".
marco's user avatar
  • 1,140
5 votes
1 answer
103 views

Scoping and closure oddities in javascript

This was presented yesterday at TC39. You can find the gist here: var p = () => console.log(f); { p(); // undefined console.log(f); // function f(){} f = 1; p(); // undefined console....
stratis's user avatar
  • 8,122
-1 votes
1 answer
106 views

Javascript hoisting confusion [duplicate]

I read Kyle's I don't know JS and came to know that function declarations will hoist first before the var. So in the below code <script> foo(); var a = true; if ( a ) { ...
Kranthi's user avatar
  • 1,417