I am just reading Kyle's "You don't know JS" book series/watch his lectures and he says, that for following code:
var a = 2;
2();
Javascript language is concerned, line two is an error. It's actually syntactically invalid. It's not a runtime problem; it's an actual authortime problem.
So in interpreted language if we was purely running line by line and we weren't doing multiple passing - we'd run line one first, and then we would discover that line two had a problem, and we'd throw an error.
But a compiled language, would say line two's problem, and it would flag you with that error before it ever tried to run line one.
"So JavaScript, in that respect, is more a compiled language than an interpreted language, because JavaScript definitely does look at line two first before it's ever tried to run line one. It looked at line one to understand what line one was about, but it didn't run it. So when you put a program like this, if that was in a file and you loaded that up into a browser, line one would never run. You'd immediately get an error saying line two is invalid."
So i tried this code in chrome's console and surprisingly it works fine, i mean a variable is going to be assigned, and if we try later console.log(a)
it prints "2".
Is it some kind of console's specific behavior or what?