hoisting Questions

1

Solved

I am getting a very strange output on the below scenarios: function test(){ var test=123; console.log(test) } // this output : 123 (function test(){ var test=123; console.log(test) })() // t...
Fortunato asked 11/3, 2017 at 18:21

2

Solved

W.r.t Hoisting of fxn definitions. if (true) { function foo() { alert(1) } } else { function foo() { alert(2) } } foo() Chrome, some 2-3 months ago - would print 2. Now,...
Naji asked 18/11, 2016 at 12:47

1

I'm making a managed .NET debugger using MDBG sample. It works for straightforward scenarios, but has issues when method rewriting occurs. Most critical parts are yield method and async methods. I...
Costin asked 13/9, 2016 at 13:35

3

Solved

As I understand it, the IIFE pattern is a work around to the fact that ES5 and below do not have a way to create block scopes. By wrapping everything in a function and immediately invoking it, we c...
Schoolroom asked 5/11, 2015 at 0:11

9

Ben Cherry's excellent article explains hoisting in JavaScript adequately. My problem, however, is that I cannot conceive a use case for this notorious perpetrator of confusion. Please explain if t...
Intervenient asked 21/12, 2011 at 22:56

5

Solved

alert(myVar1); return false; var myVar1; Above code throws error in IE, FF and Opera stating that return statement has to come in the function. But it works (shows undefined) in Safari and Chrome...
Dearing asked 16/9, 2010 at 10:0

3

So suppose I have something like this var x = 1; if (function f(){}) { x += typeof f; } x; This outputs "1undefined". I thought it should have output "1function", because function f(){} shou...
Delate asked 27/7, 2015 at 21:57

5

Solved

Edit Looks like it was an issue on my part and my usage of jsfiddle :? Ive been reading a couple of articles on hoisting lately, one is by Nicholas Zakas, and the other is by Ben Cherry. Im trying ...
Basidiospore asked 22/9, 2011 at 14:11

4

Solved

I was trying to understand the scope in JavaScript. If I declare a variable outside of a function, it is GLOBAL. Hence I tested the following code to understand sequence of execution. In the follow...
Spiny asked 4/6, 2015 at 14:52

2

Solved

My Problem Lies here I'm learning JavaScript But not new to Programming at all. I understand hoisting, but with strict mode shouldn't this produce an error and be caught either when 6 is assigned t...
Aurelio asked 31/5, 2015 at 15:55

2

Solved

I was playing around new ECMASCRIPT-6 const key word. I did not understand one particular behaviour of the keyword. Lets say I have two functions First case (function(){ console.log(_t); cons...
Fabrienne asked 27/5, 2015 at 9:34

3

Solved

I have here a simple function and a global variable. Why is myname undefined and not the string "global"? var myname = "global"; // global variable function func() { al...
Geraldgeralda asked 26/5, 2015 at 22:5

3

Solved

I'm learning JavaScript, and I feel like I understand hoisting decently enough, so I'm not asking what it is or how to do it or anything like that. Is it good to hoist? If I can, should I be...
Managua asked 21/4, 2015 at 9:14

3

Solved

I know that in the new ES6 module syntax, the JavaScript engine will not have to evaluate the code to know about all the imports/exports, it will only parse it and “know” what to load. This sounds...
Asteriated asked 29/3, 2015 at 13:26

1

Solved

As part of my learning JavaScript, I try to write code to demonstrate the concept I am learning; today I'm learning hoisted variables. Here is the code I wrote: console.log("A: My name is " ...
Sevastopol asked 30/12, 2014 at 22:23

2

In hoisting, do variables take precedence over function definition or the other way round? Please see the code below: function a() { var x = 10; function x() { return 20; } return x; }
Rhinehart asked 25/12, 2014 at 6:14

1

Solved

I wonder if this: object Foo { val regex = "some complex regex".r def foo() { // use regex } } and this: object Foo { def foo() { val regex = "some complex regex".r // use regex } } w...
Nosing asked 26/9, 2014 at 8:39

3

Running this in Chrome and Firefox gives different answers: (function() { if(true) { function f() { alert("yes"); }; } else { function f() { alert("no"); }; } f(); })(); In Chrome the r...
Monogenetic asked 9/1, 2013 at 16:59

4

Solved

I am trying to get my head around hoisting and scopes in JavaScript, and am trying to figure out what exactly happens in this block of code. console.log(outside) and console.log(local) both log und...
Towrope asked 23/7, 2014 at 5:23

1

Solved

I have the following redacted code: module.exports = { read: read, write: write, }; var read = function(parameters, config, next) { /* <snip> */ }; var write = function(parameters, conf...
Guide asked 21/5, 2014 at 19:6

5

Solved

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 kn...
Cell asked 9/3, 2013 at 13:22

5

Solved

I read the concept of Javascript Hoisting.Its pretty confusing but I saw some examples and got the idea what hoisting actually does. So basically "Hoisting is JavaScript's default behavior of movi...
Uniliteral asked 17/4, 2014 at 5:49

3

Solved

Here are 2 javascript functions var a = 10; function abcd() { alert(a);//alerts 10 a=5; } And another code is this var a = 10; function abcd() { alert(a);//alerts undefined var a=5; } In ...
Internist asked 10/3, 2014 at 18:30

2

Solved

Is there any difference between them ? I've been using both the ways but do not know which one does what and which is better? function abc(){ // Code comes here. } abc = function (){ //...

3

Solved

The value of 'a' seems to lose global scope when the constructor a is called. var a = 6; function b() { a = 10; function a() {} console.log(a); //10 } b(); console.log(a); //6
Hecatomb asked 28/5, 2013 at 23:43

© 2022 - 2024 — McMap. All rights reserved.