Skip to content

Instantly share code, notes, and snippets.

@gopal1996
Last active August 19, 2020 06:58
Show Gist options
  • Save gopal1996/d1b22136b23c1b88dee63c24a998e320 to your computer and use it in GitHub Desktop.
Save gopal1996/d1b22136b23c1b88dee63c24a998e320 to your computer and use it in GitHub Desktop.

Hoisting

Quiz 1

console.log(boo);
var boo = "boo";

var boo;
console.log(boo);
boo = "boo";

Quiz 2

function foo(){
    console.log(foo);
    var foo = "foo";
}

foo();

Quiz 3

var foo = "bar";
function greet(){
    console.log(foo);
    var foo = "foo";
}

greet();

Quiz 4

var foo = "bar";
function greet(){
    var foo;
    console.log(foo);
    foo = "bar";
}

greet();

Quiz 5

foo();
function foo(){
    console.log('Hello');
}

Quiz 6

foo();
var foo = function foo(){
    console.log('Hello');
}

Quiz 7

console.log(foo);
var foo = "foo";

Quiz 8

function foo() {
    a = 100;
    var b = 200;
}

foo();
console.log(a);
console.log(b);

Quiz 9

function bar(){
    let a = b = 0;
    return b;
}

bar();

Quiz 10

function foo() {
    console.log(a); // Output: ??
    a = 100;
}

foo();

Quiz 11

var a = 100;
function foo() {
    console.log(a); // Output: ??
    a = 200;
}

foo();

Quiz 12

function foo(){
    console.log("Hey");
}

foo();

function foo(){
    console.log("Hello");
}

Quiz 13

console.log(typeof foo);
function foo(){
    return "bar";
}
var foo = "bar";

Quiz 14

function foo(){
    return "bar";
}
var foo;
console.log(typeof foo);

Quiz 15

if(true){
    function foo(){
        console.log(1);
    }
}else{
    function foo(){
        console.log(2);
    }
}

foo();

Quiz 16

function foo(){
    bar();

    return;

    function bar(){
        console.log("bar");
    }
}

foo();

Quiz 17

var x = 7,x = 8, x;
console.log(x);

Quiz 18

function foo(x){
    x();
}
foo(function(){console.log("bar")});


function foo(x){
    x();
    function x(){
        console.log("foo");
    }
}

foo(function(){console.log("bar")});

Quiz 19

foo();

function foo() {
  console.log(1);
}

var foo = function() {
  console.log(2);
};

function foo() {
  console.log(3);
}

foo();

Quiz 20

let b, a;
function foo(){
	let a = b = 0;
	a++;
	return a;
}
foo();
console.log(typeof a);
console.log(typeof b);

Option: undefined 0 1 0

Ans: undefined 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment