How Javascript Works?

How Javascript Works?


JavaScript was created in 1995 by Brendan Eich.

  • Earlier: used only for small tasks like alerts
  • Today: used everywhere — websites, mobile apps, games, servers, even AI tools


What Can JavaScript Do?

1️⃣ Client Side (In Your Browser)

Client side means inside your browser (Chrome, Edge, Firefox).

JavaScript can:

  • Update content without reloading the page
  • Show interactive maps
  • Play videos
  • Validate forms (check email, password, etc.)
  • Show notifications and animations

Article content

Example: You like a post on Instagram and the count increases instantly — JavaScript did that.


2️⃣ Server Side (Behind the Scenes)

With tools like Node.js, JavaScript also works on the server.

It can:

  • Connect to databases
  • Save user data
  • Handle login & signup
  • Control the backend logic of websites

Example: When you log in and your data is verified — JavaScript works on the server.


3️⃣ DOM Manipulation (Changing the Page)

DOM means the structure of a web page.

JavaScript can:

  • Change text
  • Change colors
  • Hide or show elements
  • Add new content dynamically

Example: Click a button → menu opens → background color changes That instant change is called DOM Manipulation.


How JavaScript Understands Your Code?

You write JavaScript as text, but the computer understands only machine language (1s and 0s).

So JavaScript code goes through three main steps.


Phase 1: Tokenizing (Breaking into Pieces)

First, the browser breaks your code into small parts called tokens.

Example line:

const age = 25;
        

It becomes:

  • const
  • age
  • =
  • 25
  • ;

👉 Think of it like: Breaking a sentence into words and symbols so the computer can read it properly.


Phase 2: Abstract Syntax Tree (AST) – The Blueprint

Now the browser organizes those tokens into a structured form called an AST.

What is an AST?

An AST is like a blueprint or map of your code.

Example analogy:

  • You want to build a house
  • The blueprint shows where everything belongs
  • AST shows how your code is connected

If you:

  • Miss a bracket
  • Make a spelling mistake

The AST cannot be built → Syntax Error occurs.


Phase 3: Compilation (Making It Fast)

Once the AST is ready:

  • The JavaScript Engine (like Chrome’s V8) converts it into machine code
  • Machine code = 1s and 0s
  • This happens very fast, just before running the code

This process is called JIT (Just-In-Time) Compilation.

Meaning: JavaScript is compiled at runtime to make it super fast.



To view or add a comment, sign in

More articles by Srushti Khatale

  • Introduction to Java

    Java is a high-level, object-oriented programming language developed by Sun Microsystems in 1995. It is mostly used for…

  • Local Storage vs Cookies

    In JavaScript, there are three primary mechanisms for client-side data storage: cookies, local storage, and session…

  • Introduction to PostgreSQL !!

    Why PostgreSQL? PostgreSQL (Postgres) is a powerful, open-source object-relational database system. Unlike NoSQL…

  • What is MVC Structure?

    The MVC (Model-View-Controller) pattern is a software architecture that separates an application into three main…

    1 Comment
  • Understanding Actual Working of Node JS And there Endpoints!

    Imports and Setup express: Web framework for Node.js to create the server cors: Middleware to enable Cross-Origin…

    1 Comment
  • Introduction to Node JS!

    What is Node JS? Node.js is a program that lets you run JavaScript outside the browser.

    1 Comment
  • Next JS Website With SEO in 2026

    The most important thing for SEO is that page data and metadata is available on page load without JavaScript. In this…

  • Introduction to Next.Js

    Next.js is a framework built on top of React that makes it easier to create fast and modern websites.

    1 Comment
  • Rendering Techniques For Webpages!

    There are several techniques for rendering web pages-Server-Side Rendering (SSR), Client-Side Rendering (CSR), and…

  • Introduction to React

    What is React? React is a JavaScript library used for building user interfaces (UIs). It was created by Facebook and is…

    1 Comment

Others also viewed

Explore content categories