In one of the interviews i was asked whether JavaScript is interpreted or compiled language... and as per my knowledge i said with confidence it is "Interpreted"... And yes it is correct.
Then what is done in hoisting in JavaScript... it is not compiling?? (2nd question from interviewer).
Yes, there is a difference here. Hoisting does not mean compiling.
First of all, lets understand what is done in interpreted languages like java script.
Interpreted means it runs the code "line by line" and when error found it just stops at that particular line. i.e the whole code is read and understood only when running it and not beforehand.
Compiling is to convert a language into byte code for the machine to be able to read and understand.
So before running a code, there is package generated when compiling and when successful only then running of the code happens unlike JavaScript.
Finally coming to Hoisting.. it has been done by JavaScript developers in the same language where it only moves the declarations on top, not the assignments. It does not convert the code into byte-code or anything for that matter.
Hopefully my understanding are setting your understanding as well right :)
Please correct me.. if you find something wrong. (Will definitely add something to my knowledge)
Thanks for reading.
Then what is done in hoisting in JavaScript... it is not compiling?? (2nd question from interviewer).
Yes, there is a difference here. Hoisting does not mean compiling.
First of all, lets understand what is done in interpreted languages like java script.
Interpreted means it runs the code "line by line" and when error found it just stops at that particular line. i.e the whole code is read and understood only when running it and not beforehand.
Compiling is to convert a language into byte code for the machine to be able to read and understand.
So before running a code, there is package generated when compiling and when successful only then running of the code happens unlike JavaScript.
Finally coming to Hoisting.. it has been done by JavaScript developers in the same language where it only moves the declarations on top, not the assignments. It does not convert the code into byte-code or anything for that matter.
Hopefully my understanding are setting your understanding as well right :)
Please correct me.. if you find something wrong. (Will definitely add something to my knowledge)
Thanks for reading.