Interesting stuff which you might have missed in Javascript

var text = ‘outside’;

function logIt() {
console.log(text);
var text = ‘inside’;
};

logIt();

Output:
Undefined

Some expected the result of the log to be:’outside’ or ReferenceError: hoist is not defined, but instead, its output is undefined.

Reason:
JavaScript has hoisted the variable declaration.
For the interpreter, the code was like:

function logIt() {
var text;
console.log(text);
text = ‘inside’;
};

To copy an array:

var b = [1, 2, 3, 4];
var copyB = […b];

Guess the Output:

var result1 = “3” + 3; //output 33

var result2 = +”3" + 3; //output 6

var result3 = -”-3" + 3; //output 6

var result4 = -”3" + 3; //output 0

Suffering from Knowledge Quest

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store