JavaScript

A common interview question.

fork
loading
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
var x = 10;
 
function y() {
    x = 100;
    return;
    function x() {}
}
 
y();
 
console.log(x); // logs 10

 // the first occurrence of x is in the global scope.
 // The second occurrence is not available to the console.log because the function x() is hoisted.
 
 // NOTE: better familiarize myself with hoisting
Native Browser JavaScript