hoisting Questions

8

Solved

I have been playing with ES6 for a while and I noticed that while variables declared with var are hoisted as expected... console.log(typeof name); // undefined var name = "John"; ...variables de...
Banville asked 4/7, 2015 at 10:12

6

Solved

I have the following code, where I declare a function and after it, a variable with the same name as the function: function a(x) { return x * 2; } var a; alert(a); I expected this to alert und...
Olivenite asked 18/11, 2016 at 11:20

2

I was wondering how javascript hoisting works for global variable. Let's say I have following code snippet: var a = 5; function print(){ console.warn("a",a,b); var a = 10; b=5; console.warn(...
Margoriemargot asked 5/11, 2014 at 9:6

4

Solved

I understanding how hoisting in javascript occurs, functions are hoisted before variables, and only the declarations are hoisted. But When I came across hoisting inside if/else conditionals, like t...
Howerton asked 7/2, 2016 at 6:46

2

One of my projects suddenly failed to compile on a Windows laptop, where the exact same code was working on a Mac. I've read about hoisting and adding nohoist, which seemed to fix the problem for A...
Injury asked 4/11, 2021 at 13:31

5

A couple of days ago, I had an interview, and one of the questions was 'what is hoisting?' then I explained the hoisting concept thoroughly, then the interviewer asked me, 'what is the main advanta...
Trod asked 21/5, 2019 at 7:6

7

Solved

I do not fully understand why the following displays "hoisted" towards the end. var x = 'set'; var y = function () { // WHAT YOU DON'T SEE -> var x; // is effectively "hoisted" to this lin...
Culex asked 16/4, 2015 at 6:43

2

Solved

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); } console.log(fo...
Ildaile asked 23/3, 2021 at 3:46

1

class App { constructor() { this.canvas = document.createElement('canvas'); document.body.appendChild(this.canvas); this.ctx = this.canvas.getContext('2d'); this.pixelRatio = window.devic...
Jehu asked 30/12, 2020 at 17:34

2

Solved

I've read a couple of more comprehensive articles on the execution context and now I am sort of confused and messed up in the head. To keep the question as brief as possible avoiding long citations...
Elwaine asked 24/10, 2020 at 10:58

1

{function foo(){};foo=1;function foo(){};foo=2;} console.log(foo); // 1 Can anyone explain why "1" is output here? Edit: Seems there is an implementation difference, within &quo...
Thermotensile asked 18/9, 2020 at 3:1

1

The following Python program A outputs 1, as expected, while the following Python program B raises an unbound local variable x error, counterintuitively. Program A: def f(): print(x) x = 1 f() ...
Entourage asked 10/8, 2020 at 9:7

2

Solved

I am studying GraphQL and I get a bit confused from different implementations on the specific issue when writing the fields of a GraphQLObjectType. What is the difference between these two implemen...
Alceste asked 19/9, 2016 at 18:1

16

Solved

I just read a great article about JavaScript Scoping and Hoisting by Ben Cherry in which he gives the following example: var a = 1; function b() { a = 10; return; function a() {} } b(); aler...
Polyclinic asked 21/9, 2011 at 21:23

3

Solved

Why does JavaScript hoist variables? What was the rationale of the designers when they decided to implement hoisting? Are there any other popular languages that do this? Please provide relevant l...
Dendy asked 21/2, 2013 at 14:45

2

If we declare a variable and a function with same name, it is accepting re-declaration. But when we do the same thing inside a block, it shows re-declaration error. Code: var x; function x() ...
Secundine asked 12/7, 2019 at 12:11

2

Solved

function g () { var x; function y () {}; var z; } I would like to know exactly what order the above code becomes when hoisted. Theory 1: Order between vars and functions remains as-is: funct...
Edyth asked 30/1, 2015 at 23:58

1

Solved

I'm having a bit of trouble understanding why my code works. I'm expecting a reference error, but everything works fine. My code: const functionA = () => { let bResult = functionB(); ...
Shofar asked 28/2, 2019 at 20:25

3

Solved

console.log(a) //output:ƒ a(){} var a = 1; function a(){}; var a = 10; console.log(a) //output:10 ==================== var a = 1; if(true){ function a(){}; var a = 10; } console.log(a) // this...
Alage asked 11/4, 2018 at 12:9

3

Solved

I've been learning a lot of Javascript lately and I've been trying to understand the value (if there is any) of hoisting variables. I understand (now) that JS is a two pass system, it compiles and...
Kimikokimitri asked 18/10, 2018 at 17:8

5

Solved

I use both Javascript and C# on a daily basis and I sometimes have to consider hoisting when using Javascript. However, C# doesn't seem to implement hoisting(that I know of) and I can't figure out ...
Debbiedebbra asked 12/9, 2013 at 9:40

1

Solved

I'm reading the second book of the series "You don't know JS" and I've read that functions are hoisted before variables. So this is the code: foo(); // 1 var foo; function foo() ...
Bivalent asked 26/5, 2018 at 7:13

3

Consider the following code: #include <string.h> void bar(char c); void foo(const char* restrict ss) { for (int i = 0; i < strlen(ss); ++i) { bar(*ss); } } I would expect the strl...
Swordbill asked 28/1, 2018 at 0:31

2

I don't really understand what's happening with the snippet below. I would expect an error because of the Temporal Dead Zone, but it looks like const baz = '123123'; gets hoisted. What's th...
Keishakeisling asked 4/12, 2017 at 13:34

2

Solved

My understanding of an interpreter is that it executes program line by line and we can see the instant results, unlike compiled languages which convert code, then executes it. My question is, in ...
Magnesite asked 10/8, 2017 at 17:28

© 2022 - 2024 — McMap. All rights reserved.