What is JavaScript? Introduction with Hello World Example

⚡ Smart Summary

JavaScript is the programming language that makes web pages interactive. This introduction explains what JavaScript is, where it came from, how browsers and Node.js execute it, and how to write and run a first Hello World script.

  • 🌐 Client and server: JavaScript began inside the browser but now also runs on servers through Node.js, Deno, and Bun.
  • 🕰️ Origin: Brendan Eich built the language at Netscape in 1995; it was called Mocha, then LiveScript, then JavaScript.
  • 📜 Standard: ECMAScript is the official specification, so every modern browser agrees on the same core language rules.
  • 🛠️ Setup: A plain text editor and any modern browser are enough to write and test your first script.
  • 🖥️ Console first: Press F12, open the Console tab, and run single lines of JavaScript without creating any files.
  • Not Java: Java and JavaScript share four letters and almost nothing else, including type systems and runtimes.
  • Placement: Put scripts inside script tags or link an external .js file for cleaner and cacheable pages.

What is JavaScript

What is JavaScript?

JavaScript is a high-level programming language that adds behaviour to web pages. It is one of the three core technologies of the web: HTML supplies the structure, CSS supplies the appearance, and JavaScript supplies the interaction. Every time a search box shows suggestions as you type, a photo carousel slides, or a sign-up form warns you about a missing field, JavaScript is doing that work in the background.

The diagram below shows how a script sits alongside the markup of an ordinary web page.

Introduction to JavaScript

For most of its life JavaScript was described as a client-side scripting language, because it only ran inside a browser. That description is now incomplete. Since Node.js appeared in 2009, the same language has also powered web servers, command line utilities, desktop applications, and mobile apps. A more accurate description today is that JavaScript is a general purpose language with an unusually strong presence in the browser.

The characteristics that define the language are:

  • Dynamically typed: a variable can hold a number now and a string a moment later, so types are checked while the program runs.
  • Interpreted and just-in-time compiled: engines such as V8 in Chrome and Node.js compile frequently executed code into machine code for speed.
  • Multi-paradigm: imperative, functional, and object-oriented styles are all supported.
  • Event driven: code reacts to clicks, keystrokes, timers, and network responses rather than running top to bottom and stopping.
  • Single threaded with an event loop: slow work such as a network call is queued instead of freezing the page.

💡 Tip: JavaScript and ECMAScript are not competing languages. ECMAScript is the written specification, and JavaScript is the implementation of that specification that browsers and Node.js actually ship.

History of JavaScript

Brendan Eich created JavaScript at Netscape Communications in 1995, producing the first working prototype in roughly ten days. Internally the project was called Mocha. It shipped in a Netscape Navigator 2.0 beta as LiveScript in September 1995, and was renamed JavaScript in December 1995 as part of a marketing agreement between Netscape and Sun Microsystems, the company that owned Java at the time.

Javascript History

That renaming is the single reason so many beginners still assume JavaScript is a lightweight edition of Java. The two languages are unrelated in design, ownership, and runtime. Netscape submitted the language to Ecma International in 1996, and the first edition of the ECMA-262 standard was published in June 1997. The table below lists the milestones that matter most when reading older code.

Year Milestone Why it matters
1995 Mocha, then LiveScript, then JavaScript The language is created at Netscape by Brendan Eich.
1997 ECMA-262 first edition The language gains a vendor-neutral written standard.
2009 ES5 and the first release of Node.js Strict mode arrives, and JavaScript escapes the browser.
2015 ES6 (ECMAScript 2015) let, const, arrow functions, classes, modules, and promises are added.
2016 onward Yearly ECMAScript editions Smaller features ship every June instead of in rare large releases.

Because of the yearly release cycle, code written before 2015 looks noticeably different from modern code. Older tutorials use var everywhere, while current code prefers let and const when declaring variables in JavaScript.

What is JavaScript Used For?

JavaScript is no longer confined to small page tricks. The same syntax now appears in four very different places, which is why it consistently ranks as one of the most widely used languages in developer surveys.

Area What JavaScript does there Typical tools
Browser front end Handles clicks, updates the page without a reload, validates forms, and draws charts. React, Vue, Angular, Svelte
Server side Serves HTTP requests, talks to databases, and builds REST or GraphQL APIs. Node.js, Deno, Bun, Express
Mobile applications Builds Android and iOS apps from a single shared codebase. React Native, Ionic, Capacitor
Desktop applications Wraps a web interface in a native window with file system access. Electron, Tauri
Tooling and automation Bundles assets, runs test suites, and drives browsers for end-to-end testing. Vite, webpack, Jest, Playwright

Games, data visualisations, browser extensions, and small hardware projects all rely on it as well. For a beginner the practical consequence is simple: the effort you spend on syntax now transfers directly to server work, mobile work, and test automation later. If you want to see the language applied to real problems, work through a set of practical JavaScript code examples once the basics are comfortable.

How to Run JavaScript?

JavaScript does not execute by itself. It needs a host environment that contains a JavaScript engine. Chrome and Edge use V8, Firefox uses SpiderMonkey, and Safari uses JavaScriptCore. When a browser downloads an HTML page and finds a script, it hands that script to its engine, which parses, compiles, and runs it.

The second host environment is Node.js, which embeds the same V8 engine outside the browser. That is how the identical language runs on a server or in a terminal. The practical advantage of JavaScript is that every modern browser supports it on Windows, Linux, and macOS, so you rarely need to worry about which browser a visitor uses. This is a genuine improvement over VBScript, which only ever worked in Internet Explorer on Windows and is now deprecated along with Internet Explorer itself.

⚠️ Warning: Browser JavaScript and Node.js JavaScript share the core language but not the surrounding objects. document and window exist only in the browser, and require and the file system modules exist only in Node.js. Copying code between the two without checking will throw a reference error.

Tools You Need

You need a text editor to write code and a browser to view the result. Notepad++, Visual Studio Code, Sublime Text, and any other editor you are comfortable with will do the job, although an editor with syntax highlighting and bracket matching will save you a great deal of debugging. Any current browser works: Google Chrome, Firefox, Microsoft Edge, or Safari. Nothing has to be purchased or installed beyond those two items.

A Simple JavaScript Program

If you keep JavaScript inside the HTML document itself, all of the code must sit between an opening <script> tag and a closing </script> tag. This is how the browser tells your code apart from the surrounding markup. Older pages also set a type attribute, written as <script type="text/javascript">, which was needed when rival client-side languages such as VBScript existed. Modern pages omit it, because HTML5 treats text/javascript as the default. The two versions below are functionally identical, and both are still valid.

Hello World Example

The traditional first program displays a message. Place the following markup in a file named hello.html and open it in a browser.

<html>
<head>
	<title>My First JavaScript code!!!</title>
	<script type="text/javascript">
		alert("Hello World!");
	</script>
</head>
<body>
</body>
</html>

Output:

A browser dialog box opens containing the text:

Hello World!

Note: type="text/javascript" is not necessary in HTML5. The following code works exactly the same way.

<html>
<head>
	<title>My First JavaScript code!!!</title>
	<script>
		alert("Hello World!");
	</script>
</head>
<body>
</body>
</html>

Output:

A browser dialog box opens containing the text:

Hello World!

Once a page grows beyond a few lines, moving the script into its own .js file keeps the markup readable and lets the browser cache the code. The differences are covered in detail in this comparison of internal and external JavaScript.

How to Write and Run Your First Script

There are three practical ways to execute JavaScript, and a beginner should try all three because each one suits a different situation.

1. The browser console. This is the fastest option and requires no files at all. Open any web page, press F12 (or Ctrl+Shift+I on Windows and Linux, Cmd+Option+I on macOS), and select the Console tab. Type a line, press Enter, and the result appears immediately. It is the ideal place to test a single expression or to check what a function returns.

// Type each line into the browser console and press Enter
console.log(2 + 2);
console.log("Guru" + 99);
console.log(Math.max(4, 12, 7));
console.log(typeof "hello");

Output:

4
Guru99
12
string

Notice the second line. Adding the number 99 to the string “Guru” produces the string “Guru99” rather than an error, because JavaScript converts the number to text automatically. That behaviour is convenient and is also a classic source of beginner bugs.

2. An HTML file. This is the Hello World example shown above. Use it whenever the code has to touch the page itself, for example reading a form value or changing an element.

3. Node.js from the terminal. Install Node.js, save the code in a file with a .js extension, then run node first-script.js. Nothing renders, so console.log becomes your output channel. This is the route to take when you want to practise pure language features without any HTML around them.

// first-script.js
const language = "JavaScript";
const createdBy = "Brendan Eich";
const releaseYear = 1995;

console.log(language + " was created by " + createdBy + " in " + releaseYear + ".");

const usedFor = ["Interactive web pages", "Server apps with Node.js", "Mobile apps"];

usedFor.forEach(function (item, index) {
  console.log(index + 1 + ". " + item);
});

Output:

JavaScript was created by Brendan Eich in 1995.
1. Interactive web pages
2. Server apps with Node.js
3. Mobile apps

This short script already uses three ideas you will meet constantly: constants declared with const, an array holding a list of values, and a callback function passed to forEach. Rewriting the same loop with a for statement is a useful exercise once you have studied loops in JavaScript.

JavaScript vs Java

The names are the biggest accident in programming history, and the confusion they cause is worth clearing up early. JavaScript was renamed from LiveScript purely for marketing reasons in 1995, at a point when Java was the most talked-about technology on the web. The two languages were designed by different people, at different companies, for different problems.

Aspect JavaScript Java
Created by Brendan Eich at Netscape, 1995 James Gosling at Sun Microsystems, 1995
Typing Dynamic and weakly typed Static and strongly typed
Runs on Browser engines and Node.js The Java Virtual Machine
Compilation Just-in-time compiled by the engine at runtime Compiled ahead of time to bytecode
Object model Prototype based, with class syntax added in ES6 Class based from the start
File extension .js .java compiled to .class
Common use Web front ends, APIs, tooling Enterprise back ends, Android, big data

The only real similarity is that both borrow curly-brace syntax from C. Learning one does not teach you the other, although the shared syntax makes the second language slightly easier to read. If strict typing appeals to you, TypeScript adds a static type layer on top of JavaScript while compiling down to plain JavaScript, and the differences are set out in this TypeScript and JavaScript comparison.

With the basics in place, the natural next steps are interactive JavaScript exercises, then variables and data types, followed by arrays and loops. After that, object-oriented JavaScript explains how objects, prototypes, and classes fit together, and string formatting covers the text handling you will use in almost every script.

FAQs

ECMAScript is the written standard, published as ECMA-262, that defines the syntax and built-in objects. JavaScript is the working implementation of that standard shipped by browser vendors and Node.js. Version names such as ES6 refer to editions of the standard.

Both. Source code is shipped as plain text and read by the engine, but engines such as V8 and SpiderMonkey just-in-time compile frequently executed functions into machine code. The result behaves like an interpreted language with near-compiled speed.

The usual causes are a missing closing script tag, a wrong path to the external file, a typo that throws a syntax error, or a script that runs before the element it targets exists. Open the Console tab to read the exact error.

Internal scripts are fine for a few lines while you are learning. Move to an external .js file as soon as the code is reused on more than one page, because the browser can then cache it and the markup stays readable.

They can produce working snippets quickly, but they also mix browser-only and Node.js-only APIs and occasionally invent methods. Run every suggestion, read the console errors yourself, and treat the output as a draft rather than a finished answer.

It builds the chat interface, streams model responses token by token, and calls model APIs from a Node.js back end. Libraries such as TensorFlow.js and ONNX Runtime Web also run smaller models directly inside the browser.

Summarize this post with: