Home > Article > Web Front-end > Is javascript a compiled language?
Javascript is not a compiled language, but an interpreted programming language. The JavaScript source code does not need to be compiled before being sent to the client for execution. Instead, the character code in text format is sent to the browser for interpretation and execution by the browser.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
Javascript is not a compiled language, but an interpreted or just-in-time compiled programming language.
Compilation is to translate the source program into executable target code. Translation and execution are separate; while interpretation is to complete the translation and execution of the source program at one time and does not generate storable target code. .
JavaScript ("JS" for short) is a lightweight, interpreted or just-in-time compiled programming language with function priority; JavaScript is interpreted line by line during the running of the program.
The JavaScript source code does not need to be compiled before being sent to the client for running. Instead, the character code in text format is sent to the browser for interpretation and execution by the browser. The weakness of literal translation languages is that they are less secure, and in JavaScript, if one cannot run, then the following languages cannot run either. The solution is to use try{}catch(){}, in which error information will be passed in catch().
console.log("a");//这是正确的 console.log("b");//这是正确的 console.logg("c");//这是错误的,并且到这里会停下来 console.log("d");//这是正确的 console.log("e");//这是正确的 /*解决办法*/ try{console.log("a");}catch(e){}//这是正确的 try{console.log("b");}catch(e){}//这是正确的 try{console.logg("c");}catch(e){}//这是错误的,但是到这里不会停下来,而是跳过 try{console.log("d");}catch(e){}//这是正确的 try{console.log("e");}catch(e){}//这是正确的
JavaScript is classified as a literal translation language because mainstream engines load the code and interpret it every time it is run. V8 interprets all the code before starting to run it, while other engines interpret it line by line (SpiderMonkey will temporarily store the interpreted instructions to improve performance, which is called real-time compilation). However, because most of the core parts of V8 use Written in JavaScript (and SpiderMonkey is written in C), so in different tests, the performance of the two has advantages and disadvantages. Corresponding to it is a compiled language, such as C language. Before a program written in a compiled language can be run, it must be compiled to compile the code into machine code and then run.
Compiled language VS interpreted language
1. Different communication methods with computers
The interpreter does not generate targets Code, it takes out the statements in the source program one by one, interprets them, and executes them; the interpreter interprets the source code files into machine language and hands them to the CPU for execution.
Compilation is to translate the source program into executable target code and execute the executable program file. Translation and execution are separated.
2. Running speed
The interpreter program has low operating efficiency. All codes need to be interpreted and executed by the interpreter, and the speed is much slower than the compiled program.
Compiled program execution It's fast because your program code has been translated into machine language that the computer can understand.
[Related recommendations: javascript learning tutorial]
The above is the detailed content of Is javascript a compiled language?. For more information, please follow other related articles on the PHP Chinese website!