How does JavaScript Work?17 Mar 2025 | 4 min read JavaScript is a client-side scripting language and one of the most efficient, commonly used scripting languages. The term client-side scripting language means that it runs at the client-side( or on the client machine) inside the web-browsers, but one important thing to remember is that client's web-browser also needs to support the JavaScript or it must be JavaScript enabled. Nowadays, most of the modern web browsers support JavaScript and have their JavaScript engines. For example, Google Chrome has its own JavaScript engine called V8. Some other web-browsers with their JavaScript engines
It totally depends on the web-developers how they use JavaScript and for what, because it can be used for several things in web development. One of the most common uses of JavaScript is to validate data given by the user in the form fields. With the help of following example, we can understand how JavaScript works: In this example, we have created a simple HTML document and added our JavaScript code in it. Program In the above program, we just displayed a alert message to the user by using the "alert()" method that is a pre-defined method of JavaScript. We also used the "console.log();" method and passed "JavaScript" as the String and in the inspect mode we can see "JavaScript" in the console as shown in the below output. Output ![]() As we can see in the output, the programs run fine on our web browser. Here another question that comes out "how the browser understands the JavaScript code and runs it." Mostly every web browsers nowadays have their own JavaScript engines, as we have discussed above. So, it is the JavaScript engine that understands the code and runs it. Now let's see how the JavaScript engine handles and runs .js code. In this case, we have used a chrome browser to run our program that has the "V8" JavaScript engine, which is also used for creating the Node.js. As we already know, JavaScript is an interpreted language that means it gets executed in line by line manner (or which means the JavaScript engine converts the Js code line by line and runs in the same manner instead of converting the whole program once). We can understand how a typical JavaScript engine works with help of a diagram: ![]() Whenever we run a JavaScript program inside a web browser, JavaScript code is received by the browser's engine and the engine runs the source code to obtain the output. In a standard JavaScript engine, the source code goes through several steps and gets executed as you can see in the above given diagram. Let us understand each of these steps in more detail. Step 1: Parser This is the first stage of the engine, every time we run a JavaScript program, our code is first received by the "parser" inside the JS engine. The parser's job is to check the JavaScript code for syntactic errors in line by line manner because JavaScript is an interpretive scripting language, so whenever an error is detected by the parser, it throws a kind of error and stops execution of the code. In short, we can say that it parses JavaScript code. Step 2: AST Once the parser checks all JavaScript codes and gets satisfied that there are no mistakes/errors in the code, it creates the data structure called AST (it stands for Abstract Syntax Tree). We can easily understand what is AST with help of following example. Example Let's suppose we have a JavaScript program as given below: Program Once the parser checks the above JavaScript code, it will create a data structure called AST as we have already discussed above. The created AST (Abstract Syntax Tree) looks like the given image. ![]() Note: It is not the exact abstract syntax tree, but it is the pictorial representation of the Abstract Syntax Tree.Step 3: Conversion to Machine code Once the Abstract Syntax Tree is created by the parser, the JavaScript engine converts the JavaScript code into the machine code (or in the language that machine can understand). Step 4: Machine code When the program written in the JavaScript gets converted in the machine language (or in byte code), the converted code is sent to the system for execution, and finally, that byte code run by the system/engine just like we observe in our first example. Next TopicHow to debug JavaScript |
In this chapter, you will learn how to generate random images on a webpage with the help of JavaScript. So, we will create different random image generator using JavaScript and HTML source code. Firstly, it requires an array to contain the URLs of images to...
8 min read
What is an URL? A URL is another name for a web address. For instance, a word-based URL is TpointTech.com. A URL can also be created using an IP address (ex. 192.168.2.24). Most consumers provide the name's address when conducting an online search because names are...
3 min read
If you know how to set a password in a JavaScript code, it becomes easy to understand how we can toggle the visibility of the password. Here, in this section, we will learn how we can toggle the visibility of the password in JavaScript by implementing...
3 min read
Text to Particles Dissolve Effect JavaScript & CSS In this article, we will understand how to create example of text to particles dissolve effect by using JavaScript & CSS. Particles dissolve effect is used for creating animated, interactive, configurable particle animations on a Canvas element that...
6 min read
In this article, we will understand the gif player using CSS and JS. The GIF Player library enables you to play, pause an animated GIF file just like a video player. It works in modern browsers and IE8+. Following are the various examples of gif player...
7 min read
Window.location is used to provide a Location object with details about the document's current location. This Location object reflects the location (URL) of the object it's linked to, i.e., it holds information about the current content location (host, href, etc.) JavaScript Location Object The window.location attribute represents...
8 min read
? JavaScript offers three in-built functions to add or insert objects in an array. These methods are - push() splice() unshift() You can use any of these methods to add the objects to the array. Objects are the elements or values in the array. We will discuss each method in...
9 min read
An Http cookie, also known as a web cookie, is a small piece of data that the server sends to the web browser. The browser may store the cookies and send them back to the server with other requests. The typical use of the cookies...
10 min read
A CSS Style Declaration object results from the getComputedStyle() function. It is provided elements of the CSS properties and values using the javascript windows getComputedStyle() function. The element displays various sources of styling using computed style in the tag. Syntax The following syntax shows the windows getComputedStyle()...
4 min read
JavaScript can access the global object using the global object property. The global object in JavaScript is called a window in a web browser. It is also referred global or web worker, Depending on the environment. The JavaScript frameworks with web servers use the globalThis...
3 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India