Tutorials Logic, IN info@tutorialslogic.com
Navigation
Home About Us Contact Us Blogs FAQs
Tutorials
All Tutorials
Services
Academic Projects Resume Writing Website Development
Practice
Quiz Challenge Interview Questions Certification Practice
Tools
Online Compiler JSON Formatter Regex Tester CSS Unit Converter Color Picker
Compiler Tools

What Is JavaScript? Beginner Guide, Uses & Examples

What is JavaScript?

JavaScript is a lightweight, interpreted, multi-paradigm programming language created by Brendan Eich in 1995 at Netscape. Originally named Mocha, then LiveScript, it was renamed JavaScript as a marketing decision. Today it is the world's most widely used programming language - the only language that runs natively in web browsers.

  • Client-side: Runs in the browser - manipulates DOM, handles events, validates forms
  • Server-side: Runs on Node.js - builds REST APIs, web servers, CLI tools
  • Mobile: React Native, Ionic - cross-platform mobile apps
  • Desktop: Electron - VS Code, Slack, Discord are built with it

JavaScript Versions (ECMAScript)

JavaScript is standardized by ECMA International as ECMAScript (ES). Since ES2015 (ES6), new versions are released annually.

VersionYearKey Features
ES52009strict mode, JSON, Array methods (forEach, map, filter)
ES6 / ES20152015let/const, arrow functions, classes, modules, promises, template literals
ES20162016Array.includes(), exponentiation operator (**)
ES20172017async/await, Object.entries(), Object.values()
ES20182018rest/spread for objects, Promise.finally(), async iteration
ES20192019Array.flat(), Array.flatMap(), Object.fromEntries()
ES20202020Optional chaining (?.), nullish coalescing (??), BigInt, Promise.allSettled()
ES20212021String.replaceAll(), Promise.any(), logical assignment (&&=, ||=, ??=)
ES20222022Array.at(), Object.hasOwn(), class fields, top-level await
ES20232023Array.findLast(), Array.toSorted(), Array.toReversed()
ES20242024Promise.withResolvers(), Object.groupBy(), Map.groupBy()

Your First JavaScript Program

You can run JavaScript in three common places: inside the browser console, inside an HTML page using a <script> tag, or outside the browser with Node.js. Beginners usually start in the browser because they can immediately see JavaScript interact with the page.

Hello World
// In browser - open DevTools Console (F12) and type:
console.log('Hello, World!');

// In HTML file
// <script src="script.js"></script>
// or inline:
// <script>alert('Hello!');</script>

// Variables
let name = 'Alice';        // mutable
const age = 25;            // immutable
var old = 'avoid var';     // function-scoped (legacy)

// Template literals
console.log(`My name is ${name} and I am ${age} years old.`);

// Modern features
const user = { name: 'Bob', address: { city: 'Delhi' } };
console.log(user?.address?.city);  // Optional chaining: 'Delhi'
console.log(user?.phone ?? 'N/A'); // Nullish coalescing: 'N/A'

How JavaScript Runs in the Browser

When a browser opens a web page, it reads the HTML, builds a document object model called the DOM, applies CSS styles, and then runs JavaScript. JavaScript can read the DOM, change text, add or remove elements, respond to button clicks, validate forms, and request data from APIs.

Browser Example
// HTML: <button id="saveBtn">Save</button>
const button = document.querySelector("#saveBtn");

button.addEventListener("click", function () {
  button.textContent = "Saved";
  button.classList.add("is-success");
});

This is why JavaScript is called the language of the web. HTML gives the page structure, CSS gives it style, and JavaScript adds behavior.

JavaScript Execution Model

JavaScript runs on a single main thread in the browser. That means one piece of JavaScript code runs at a time. Slow work such as timers, network calls, and user events is handled asynchronously through the event loop, so the browser can stay responsive while waiting for those tasks to finish.

Event Loop Idea
console.log("First");

setTimeout(function () {
  console.log("Third");
}, 0);

console.log("Second");

// Output:
// First
// Second
// Third

The timer callback runs later, even with a delay of 0, because callbacks wait until the current synchronous code finishes. This same idea is used by events, promises, fetch(), and async/await.

JavaScript vs Java

Despite the similar name, JavaScript and Java are completely different languages. JavaScript is dynamically typed, interpreted, and runs in browsers. Java is statically typed, compiled to bytecode, and runs on the JVM. The name similarity was purely a marketing decision in 1995.

Key Takeaways
  • JavaScript was created in 10 days by Brendan Eich in 1995 - originally called Mocha, then LiveScript.
  • ECMAScript is the official standard. ES6 (2015) was the biggest update - introduced classes, modules, arrow functions.
  • JavaScript is the only language that runs natively in all web browsers.
  • Node.js (2009) brought JavaScript to the server - enabling full-stack JS development.
  • Use let and const (ES6+) - avoid var which has confusing function-scoping behavior.

Ready to Level Up Your Skills?

Explore 500+ free tutorials across 20+ languages and frameworks.