What is Javascript and How It Powers Modern Websites ๐Ÿš€

Sangy KSangy K
8 min read

Picture this: You click a button on a webpage, and absolutely nothing happens ๐Ÿ˜ถ๐Ÿšซ.

There are no dropdown menus to explore, no fun animations to enjoy, and no validations on form submissions.

Basically, a lifeless piece of the internet.

That's what the web would look like without Javascript. ๐Ÿ˜ตโ€๐Ÿ’ซ

What is Javascript? ๐Ÿค”

Javascript, often abbreviated as "JS", is the wacky genius of modern web development.

It's the magic wand ๐Ÿช„ that transforms static, boring HTML and CSS websites into lively, interactive, and engaging experiences that are hard to stop scrolling through.

Simply put, Javascript is a programming language that adds interactivity, animations, and dynamic features to websites. Whether it's a pop-up (๐Ÿ™„), a dropdown menu (๐Ÿ”ฝ), or an animation that dances across your screenโ€”Javascript is behind the curtain pulling the strings.

It's one of the holy trinity of web development: โ€ข HTML โ€“ gives structure ๐Ÿงฑ โ€ข CSS โ€“ makes it pretty ๐Ÿ’… โ€ข Javascript โ€“ brings it to life โšก

It's primarily a client-side language*, **event-driven*, and runs directly in your browser without requiring installation. Magic? Nopeโ€”just good old scripting.

Oh, and it also works on the server side, but we'll dive into that later.

๐Ÿ“œ A Brief History of Javascript

Back in 1995, Brendan Eich developed Javascript in just 10 days. Yes, that's faster than most of us write a to-do list ๐Ÿ“.

Originally called Mocha (mmm, coffee), then Live Script, it was finally rebranded as Javascript because, hey, Java was trendy at the time โ˜•.

Despite the misleading name, Java โ‰  Javascriptโ€”that's like comparing ham to a hamster.

Fast-forward to today. Javascript has grown from a toy language into one of the web's core technologies, alongside HTML and CSS. It is now standardised under ECMAScript and powers everything on the web except your morning coffee ๐Ÿต.

โœจ Core Features of Javascript

Javascript isn't just pretty codeโ€”it's flexible, feisty, and full of surprises.

  • Dynamically Typed โ€“ like, whatever ๐Ÿ˜Ž

  • Event-Driven โ€“ reacts to user clicks, scrolls, and tantrums ๐Ÿคจ.

  • Fast โ€“ thanks to powerful browser engines โšก

  • Versatile โ€“ works on browsers, servers, phones, fridges (not kidding ๐Ÿ˜œ!)

It's like that colleague who can debug complex code with ease, seamlessly integrate APIs, and always finds time to collaborate on projects. ๐Ÿ’ป

๐Ÿ˜‡How to Run Javascript in a Browser

Javascript is built right into all major browsers (Chrome, Firefox, Safari, Edge), like a secret snack drawer ๐Ÿซ.

You can run Javascript in the browser in a few simple ways:

1. The Developer Console (For Quick Testing)

  1. Open Chrome (or any browser).

  2. Press F12 or right-click โ†’ Inspect.

  3. The browser's developer tools will open up. Go to the Console Tab.

Type this, Hit Enter and watch the magic unfold ๐ŸŽฉโœจ

console.log("Hello, World! ๐Ÿš€");

2. Add it directly to HTML

Use the <script> tag inside your HTML file - index.html:

<!DOCTYPE html>
<html>
    <body>
        <h1>Javascript Test</h1>

        <script>
            alert("Hello, World! ๐Ÿš€");
        </script>
    </body>
</html>

Open the index.html file in your favorite browser.

Boom!๐Ÿ’ฅ JS is live and will greet you like a chatty bot!.

๐ŸŒHow Javascript gets executed

Before getting our hands dirty with Javascript code, it is better to have a basic understanding of how Javascript gets executed. โ˜„๏ธ

Javascript alone is just syntax and logic; just like any other programming language, a compiler or an interpreter is needed to execute Javascript.

Well, there are still ongoing debates about whether Javascript is a compiled language or an interpreted language. It would be more accurate to say that Javascript in modern times is both compiled and interpreted, specifically through JIT (Just-In-Time) Compilation. More on this later.

To interact with web pages, forms, user events, or fetch data, it requires a host where this JIT Compiler (a Javascript engine) is embedded, much like the engine of a carโ€”essential for driving the experience forward and making everything run smoothly. ๐Ÿš—

What Is a Hosted Environment? โš™๏ธ

A hosted environment โ€” or, as seasoned developers call it, the runtime environment โ€” is the setup provided by the host system, such as a web browser or Node.js, that embeds and interacts with the Javascript engine. This environment offers some juicy extras โ€” such as fetch, document, and setTimeout โ€” that the core Javascript language doesn't include.

Key Examples of Hosted Environments for Javascript

  1. Web Browsers (Client-side Hosted Environment)

    • DOM access: via document, window

    • Browser APIs: like fetch(), alert(), console.log()

    • Timers: setTimeout, setInterval. etc

Characteristics:

  • Code runs in the context of a webpage.

  • Controlled by the browser's security and event loop.

  • Can access and manipulate the DOM.

  1. Node.js (Server-side Hosted Environment)

    • File System: via fs

    • Network: http

    • Other APIs: process, require, etc.

      Characteristics:

      • Code runs on a server, often with access to the filesystem and network.

      • No DOM or browser-specific features.

      • Includes an event-driven, non-blocking I/O model.

  2. Other Examples:

    • Deno: Secure TypeScript/Javascript runtime with modern APIs.

    • Edge Functions / Serverless Platforms: Cloud-hosted Javascript executed in response to HTTP requests.

All major browsers have Javascript engines built into them (Chrome, Firefox, Safari, Edge)

Some well-known JS engines are,

  • Chrome โ†’ V8 Engine ๐Ÿš—

  • Firefox โ†’ SpiderMonkey ๐Ÿ’

  • Safari โ†’ JavaScriptCore ๐Ÿ

What happens when you load a web page?

So, how exactly does Javascript run when you load a web page? ๐Ÿค”

Here's a simplified overview that doesn't require a PhD:

  1. You load a page โ€“ Browser reads the HTML and finds a <script> tag.

  2. The Javascript engine (like V8 in Chrome or SpiderMonkey in Firefox) kicks in.

  3. The engine parses the code, converts it into something called bytecode or machine code.

  4. It executes the code line by line, handling events, functions, loops, and more.

  5. It interacts with the browser's APIs, including the Document Object Model (DOM) and the Browser Object Model (BOM), to enable engaging functionality on the screen.

The way everything unfolds within the browser and our Javascript engine is a fascinating process, which we will explore in more detail in a future article๐Ÿง .

๐Ÿ“Ž How to Add Javascript to a Website

There are three classic ways to add Javascript:

๐Ÿ“ 1. Inline Javascript

Directly inside HTML elements.

<button onclick="alert('You clicked!')">Click me</button>

โœ… Easy to test. โŒ Not scalable or maintainable

๐Ÿง  2. Internal Scripts in <script> Tags

In a <script> in the HTML.

<script>
    console.log("This runs when the page loads.");
</script>

Great for small scripts during development.

๐Ÿ“‚ 3. External Javascript Files

In a separate HTML file - index.html

<!-- In index.html - Withing <body> tag -->
<script src="script.js" defer></script>

Inside script.js:

// script.js
console.log("This is coming from an external file.");

๐Ÿ’ก Use defer to make sure the script runs after the HTML has loaded.

๐Ÿ‘Best practice: Keeping your Javascript in a separate .js file helps to create cleaner and easier-to-manage code. No one likes spaghetti code. ๐Ÿ

โšก How Javascript Powers Modern Websites

Javascript is the heartthrob of modern web design โค๏ธ. Well, yeah, no second thoughts on that.

It's everywhere, like the air we breathe ๐Ÿซ, and it's lightning-fast โšก.

It transforms static pages into dynamic, interactive experiences. From simple interactions like button clicks to full-scale SPAs (Single-Page Applications) that feel like native apps, Javascript is the engine driving modern UX.

With powerful frameworks like React, Vue, and Svelte, and back-end tools like Node.js, Javascript isn't just hanging out in the browser anymoreโ€”it's running the whole show, front to back. There's literally a JS tool for everything.

If modern web design were a kitchen, HTML would be the recipe, CSS the presentation on the plate, and Javascript the chef, making the magic happen in real-time. ๐Ÿง‘โ€๐Ÿณ๐Ÿง‘โ€๐Ÿณ

๐Ÿค Client-side vs Server-side Javascript

Client-Side (Browser)

It runs on your Devices ๐Ÿ’ป. It controls UI and responds to events.

Examples - React, Vue, Angular, etc

Server-Side (Node.js)

It runs on a remote server ๐Ÿ—„๏ธ. It handles data, APIs and back-end logic.

Examples - Express, NestJS, etc

Core Javascript ๐Ÿ’ช lays the foundation, and all the frameworks and libraries ๐Ÿ› ๏ธ๐Ÿš€ build on top of it.

โš ๏ธ Challenges and Limitations

It's not all sunshine and syntax.

  • Security โ€“ Cross-site scripting can be nasty ๐Ÿ•ต๏ธ

  • Browser quirks โ€“ Some browsers love being extra ๐Ÿ™ƒ

  • Messy code โ€“ Write it clean or watch your app turn into spaghetti ๐Ÿ

  • Performance issues: Heavy scripts can slow your site down to turtle speed ๐Ÿข

  • Debugging hell: Sometimes finding that one missing semicolon feels like searching for a needle in a haystack ๐Ÿชก

But hey, every hero has their flawsโ€”Javascript's just keeping things spicy ๐ŸŒถ๏ธ๐Ÿ˜Ž.

๐Ÿ”ฎ The Future of Javascript

Javascript isn't going anywhere except everywhere. It's growing wiser, faster, and maybe just a little weirder (in a good way). Here's what's cooking:

๐Ÿ’ช Web Assembly (Wasm): Javascript's hitting the gym. With Wasm, it's teaming up with languages like Rust and C++ to tackle tasks it was never built for, such as hardcore gaming, video editing, and heavy-duty number crunching โ€” all in your browser. JS + Wasm = power couple of the web.

๐Ÿ‘” TypeScript: Javascript's awkward teen years are over. TypeScript is helping it adult properly, giving it types, better tooling, and fewer "undefined is not a function" moments.

๐Ÿง  AI and Smart Tooling: Development tools are becoming increasingly intelligent. Imagine writing code and your editor gently whispering, "Hey, you forgot a semicolonโ€ฆ again." AI-assisted coding (hello, Copilot and beyond) is making Javascript dev life faster, easier, and slightly creepier.

๐Ÿš€ Framework Wars 2.0: React, Vue, Svelte, Solid, Qwik, and friends are all pushing the boundaries of fast, reactive UI. The future is about smarter rendering, less Javascript shipped to the browser, and fewer "why is my page load 3MB" moments.

โš™๏ธ Server-side Evolution: Node.js, Deno, Bun โ€” everyone's racing to make server-side Javascript faster, leaner, and cooler. Serverless functions and edge computing are making it possible to run Javascript anywhere... even on a fridge (probably).

๐Ÿ”— Universal Everything: Full-stack Javascript is now the norm. Front-end, back-end, mobile apps, desktop apps, even IoT โ€” all running Javascript. Pretty soon, your toaster ๐Ÿž might be sending JSON logs ๐Ÿ“Š straight to your console ๐Ÿ–ฅ๏ธโ€”because even breakfast needs debugging ๐Ÿ˜….

๐ŸŽ‰ Conclusion

Javascript isn't just codeโ€”it's the spark that makes the web come alive โšก. Without it, your site is basically a mannequin in a shop window ๐Ÿ›‘๐Ÿ‘—. But with Javascript? Boomโ€”now you've got Iron Man flying across your screen ๐Ÿฆพ๐Ÿš€.

So go ahead, crack open that browser console ๐Ÿ’ป.

Build stuff ๐Ÿ—๏ธ. Break stuff ๐Ÿ’ฃ. Fix stuff ๐Ÿ”ง. Repeat ๐Ÿ”.

That's the Javascript way ๐Ÿ˜Ž๐Ÿ”ฅ.

0
Subscribe to my newsletter

Read articles from Sangy K directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Sangy K
Sangy K

An Introvert Coder | Trying to be a Full-stack Developer | A Wannabe Content Creator