JavaScript Introduction

Beginner
⏱️ 15 min read
📚 Updated: Jul 2026
🎯 5 Examples
browser · Node.js · DOM

What You’ll Learn

This page is a self-contained introduction to JavaScript (JS)—the language that powers interactive websites. You will understand what JavaScript is, how engines run your code, and write your first programs for the browser and console.

01

What is JS

Language overview.

02

History

Brendan Eich.

03

How it works

Engine & DOM.

04

Hello World

First program.

05

Open source

ECMAScript.

06

Examples

Hands-on code.

🤔 What is JavaScript?

JavaScript (often shortened to JS) is a popular programming language used for creating interactive and dynamic web content. It is primarily used for front-end web development, allowing developers to add dynamic effects, animations, and functionality to web pages.

JavaScript can also power back-end development through Node.js, build mobile apps with React Native, create games, and even control robots and IoT devices. It is one of the most widely used languages in the world.

Together with HTML (structure) and CSS (style), JavaScript completes the trio of core web technologies. HTML builds the page skeleton; CSS makes it look good; JavaScript makes it do something when users click, scroll, or submit forms.

💡
Beginner tip

Learn basic HTML and CSS first, then add JavaScript to change text, respond to clicks, and fetch data. You will see results immediately in the browser.

👤 Who Created JavaScript?

Brendan Eich is known as the creator of JavaScript. He built the first version in just 10 days in May 1995 while working at Netscape Communications Corporation.

The language was originally called Mocha, then renamed LiveScript, before finally becoming JavaScript. Eich continued to shape the language and later co-founded the Mozilla project. Today JavaScript is standardized as ECMAScript by TC39.

Version / EventYearHighlight
JavaScript created1995Brendan Eich, Netscape (10 days)
ECMAScript 11997First official standard
AJAX era~2005Dynamic pages without full reloads
ES52009Strict mode, JSON support
Node.js released2009JavaScript on the server
ES6 / ES20152015let, const, classes, modules, arrow functions
Annual releases2016+ES2016, ES2017, async/await, etc.
ES20242024Array grouping, improved RegExp

⚙️ How Does JavaScript Work?

When JavaScript runs, the browser or Node.js loads your code into a JavaScript engine (such as V8 in Chrome and Node, or SpiderMonkey in Firefox). The engine parses source code, compiles it to optimized machine code (often via JIT compilation), and executes it.

During execution, the engine manages memory and handles asynchronous work through an event loop—timers, network responses, and user events are queued and processed without blocking the main thread.

In the browser, JavaScript can interact with the Document Object Model (DOM)—a tree representation of HTML—to read and update page content, styles, and event listeners in real time.

📖 Is JavaScript Easy to Learn?

JavaScript is generally considered approachable, especially if you have prior programming experience. You can see immediate results in the browser console or with console.log in Node.js.

That said, JavaScript has quirks—type coercion, this binding, and asynchronous patterns—that take time to master. With dedication and practice, becoming proficient is absolutely achievable.

  • Start with variables, strings, numbers, and if/for loops
  • Use browser DevTools (F12 → Console) to experiment instantly
  • Build small projects: a calculator, todo list, or button that toggles text
  • Read error messages carefully—they usually name the line and problem

📝 Hello World in JavaScript

Here is a simple JavaScript program that prints Hello, World! to the console:

script.js
console.log("Hello, World!");
Try It Yourself

Run it with node demo.js in a terminal, or paste the line into your browser’s DevTools Console.

Basic syntax rules

  • Statements often end with ; (optional in many cases, but good habit)
  • Strings use single ' or double " quotes (or backticks for templates)
  • Comments// line or /* block */
  • Case-sensitivemyVar and myvar are different
  • Functionsfunction name() { } or arrow () => { }

💻 How to Run JavaScript

You can run JavaScript in three common ways while learning:

terminal
node demo.js
Try It Yourself
index.html
<script>
  console.log("Hello from the browser!");
</script>
Try It Yourself
  • Browser Console — press F12, open Console, paste code, press Enter
  • HTML script tag — embed JS in a page or link an external .js file
  • Node.js — run server-side scripts and tools from the terminal

🔓 Is JavaScript Open Source?

Yes. JavaScript is standardized as ECMAScript, an open specification maintained by TC39. Implementations—V8, SpiderMonkey, JavaScriptCore—are open-source projects you can read, use, and contribute to.

You do not need a license to write JavaScript. Frameworks and tools built on top (React, Vue, Node.js, Express) are also overwhelmingly open source.

🧰 Core Building Blocks

ConceptWhat it does
Variableslet, const store data
Data typesString, number, boolean, object, array, null, undefined
OperatorsArithmetic, comparison, logical
Control flowif, else, switch, loops
FunctionsReusable blocks of code
Objects & arraysGroup related data and methods
DOM APIRead and update HTML from JS
AsyncPromises, async/await, fetch

⚡ Quick Reference

TaskExample
Printconsole.log("Hi");
Variableconst age = 20;
Conditionif (x > 0) { ... }
Loopfor (let i = 0; i < n; i++) { ... }
Functionfunction add(a, b) { return a + b; }
Select DOMdocument.getElementById("msg")

Examples Gallery

Seven starter programs. Use View Output to preview here, or open Try It Yourself to edit and run live in the browser.

Example 1 — Hello, World!

script.js
console.log("Hello, World!");
Try It Yourself

Example 2 — Variables and types

script.js
const name = "Alex";
let age = 20;
const isStudent = true;

console.log(`Name: ${name}`);
console.log("Age:", age);
console.log("Student:", isStudent);
Try It Yourself

Use const for values that won’t be reassigned; use let when the value changes.

Example 3 — A simple function

script.js
function add(a, b) {
    return a + b;
}

console.log("Sum =", add(3, 5));
Try It Yourself

Example 4 — Even or odd with if-else

script.js
const n = 7;

if (n % 2 === 0) {
    console.log(n, "is even");
} else {
    console.log(n, "is odd");
}
Try It Yourself

Example 5 — Update the page (DOM)

index.html
<p id="greeting">Loading...</p>
<button id="btn">Say Hello</button>

<script>
  document.getElementById("btn").addEventListener("click", function () {
    document.getElementById("greeting").textContent = "Hello, JavaScript!";
  });
</script>
Try It Yourself

This is how front-end interactivity works: JavaScript listens for events and updates the DOM.

📚 Why Learn JavaScript?

  • Everywhere on the web — runs in all major browsers without plugins
  • Full-stack path — same language for front-end (React, Vue) and back-end (Node.js)
  • Huge job market — one of the most in-demand skills in tech
  • Instant feedback — see results in the console or browser immediately
  • Rich ecosystem — npm packages, frameworks, and tools for almost any task
  • Gateway language — concepts transfer to TypeScript, Python, and other languages

📋 JavaScript vs Other Languages

LanguagePrimary useBest for beginners when…
JavaScriptWeb front-end, Node.js APIsYou want to build interactive websites and full-stack apps
PythonScripts, data science, automationYou prefer readable syntax and data/ML focus
JavaEnterprise, AndroidYou want strong typing and OOP on the JVM
HTML / CSSStructure and stylingYou are laying out pages (pair with JS for behavior)

🧠 How JavaScript Runs in the Browser

1

Load HTML & scripts

The browser downloads your page and JavaScript files (inline or external).

Parse
2

Engine compiles JS

V8 or similar parses code, optimizes hot paths, and executes bytecode.

Execute
3

DOM & events

Scripts query the DOM, attach listeners, and respond to clicks and input.

Interact
=

Live, dynamic page

Content updates, animations run, and fetch loads data without full reloads.

Summary

  • JavaScript (JS) is the core scripting language of the web, created by Brendan Eich in 1995.
  • It powers front-end interactivity, back-end servers (Node.js), and many other platforms.
  • Engines compile and run JS; the event loop handles async work; the DOM connects JS to HTML.
  • Start with console.log("Hello, World!"); in Node or the browser console.
  • JavaScript is standardized as ECMAScript and is open source in practice.
  • Learn HTML/CSS first, then JS, then libraries like jQuery or frameworks like React.

💡 Best Practices

✅ Do

  • Use const by default; let when reassignment is needed
  • Prefer === over == for comparisons
  • Use meaningful names (userCount, not x)
  • Open DevTools and read console errors from top to bottom
  • Type examples yourself instead of only reading them
  • Validate user input before using it in the DOM

❌ Don’t

  • Use var in new code (prefer let/const)
  • Assume JavaScript and Java are the same language
  • Put sensitive logic or secrets in front-end JavaScript
  • Skip learning async before calling APIs in production apps
  • Copy stack-overflow snippets without understanding them
  • Ignore strict equality and wonder why 0 == false is true

❓ Frequently Asked Questions

JavaScript (often abbreviated JS) is a versatile programming language used to create interactive web pages, server APIs with Node.js, mobile apps, games, and more. It runs in every major browser and is one of the core technologies of the web alongside HTML and CSS.
No. Despite similar names, they are unrelated languages. JavaScript was created for browsers; Java targets enterprise and Android. Syntax has some superficial similarities, but they differ in design, typing, and runtime.
Yes for basics. You can write hello world and simple interactivity quickly. Advanced topics—closures, async/await, prototypes, and frameworks—take more practice. Prior programming experience helps, but many beginners start with JavaScript.
Save code as demo.js and run node demo.js if you have Node.js installed. Or open browser DevTools (F12), paste code in the Console, or embed it in an HTML script tag and open the page in Chrome, Firefox, or Edge.
The ECMAScript language specification is an open standard. Major engines—V8 (Chrome/Node), SpiderMonkey (Firefox), JavaScriptCore (Safari)—are open source. You use JavaScript freely without licensing fees.
Practice variables, functions, arrays, and DOM manipulation. Then learn async JavaScript, fetch API, modules, and a framework like React or Vue if you build SPAs. For backends, explore Node.js and Express.
Did you know?

JavaScript was created by Brendan Eich in just 10 days in May 1995 while he was working at Netscape. The language went through names Mocha and LiveScript before becoming JavaScript—marketing chose the name to ride Java’s popularity, even though the two languages are unrelated.

Try It Yourself

Edit any example from this page in the live Try It editor.

Open Try It editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

14 people found this page helpful