JavaScript Features

Why should you care about JavaScript Features?

When you understand JavaScript features, the language stops feeling random and starts feeling logical. You write better code faster because you know which strengths to use in real projects.

In this tutorial, we will walk through the core features that make JavaScript practical and powerful. You will keep seeing these concepts throughout your learning journey, so this overview will make upcoming topics much easier.

Note: Each feature is explained in depth in later lessons. Treat this page like your quick reference whenever you need a refresher.

JavaScript is a high-level language, which means its code reads almost like English. You don't have to worry about hardware details like memory addresses or CPU instructions.

Other high-level languages include Python, Java, and C#. They all share this beginner-friendly trait of being easy to read and write.

javascript

// JavaScript reads almost like plain English
let ages = [12, 25, 17, 30, 15];

// Find all adults (18 and over) in one readable line
let adults = ages.filter(function(age) {
  return age >= 18;
});

console.log(adults); // [25, 30]

// A low-level language would require you to manually
// manage memory addresses and CPU register values.
// JavaScript handles all of that for you automatically.

JavaScript

Java

Python

When your JavaScript code runs, it uses memory. Sometimes, it creates things that are no longer needed. Garbage collection is JavaScript's way of automatically cleaning up that unused memory.

Imagine a self-cleaning kitchen. You cook (write code), and the leftovers (unused memory) get cleaned up for you. You never have to manually free memory in JavaScript, which saves you from a whole category of bugs called memory leaks.

garbage javascript garbage javascript

javascript

// Step 1: Create an object and memory is allocated
let user = { name: "Alice", age: 30 };
console.log(user.name); // Alice

// Step 2: Remove the only reference to it
user = null;

// The object { name: "Alice", age: 30 } is now unreachable.
// JavaScript's garbage collector frees that memory automatically.
// You never have to do it yourself.
console.log(user); // null

JavaScript does not require a manual compile step before you run it. Browsers execute it directly using JavaScript engines such as V8 (Chrome), SpiderMonkey (Firefox), and JavaScriptCore (Safari).

To improve speed, engines use Just-In-Time (JIT) compilation. Frequently used code gets optimized into machine code while your program is running. You get the flexibility of an interpreted language with strong runtime performance.

Interpreter

javascript

// JavaScript runs line by line, no manual compile step needed

console.log("Line 1 runs first");
console.log("Line 2 runs second");
console.log("Line 3 runs third");

// JIT kicks in behind the scenes to make hot code fast.
// From your perspective: just write the code and run it.
let score = 42;
console.log("Score:", score); // Score: 42

JavaScript supports multiple programming styles (called "paradigms"). You're not locked into one way of writing code.

You can write event-driven code ("when this button is clicked, do this"), object-oriented code (organizing code into reusable objects), or functional code (using small, reusable functions). This flexibility is one of JavaScript's biggest strengths.

javascript

// Three programming styles, all produce the same result: 120

// 1. Procedural: step-by-step instructions
let price = 100;
let tax = price * 0.2;
console.log("Procedural:", price + tax); // 120

// 2. Object-Oriented (OOP): data and logic grouped together
let order = {
  price: 100,
  taxRate: 0.2,
  total() { return this.price + this.price * this.taxRate; }
};
console.log("OOP:", order.total()); // 120

// 3. Functional: small, reusable pure functions
function addTax(p, rate) { return p + p * rate; }
console.log("Functional:", addTax(100, 0.2)); // 120

In JavaScript, objects can inherit properties and behaviors from other objects through something called a prototype. A prototype is essentially a template that an object can look up to.

Every object has a hidden link to its prototype (accessed via __proto__). When you try to use a property that doesn't exist on an object, JavaScript automatically checks its prototype, then that prototype's prototype, and so on. This chain is called "prototype-based inheritance." We'll cover this in detail later.

prototype

javascript

// Every object can inherit from another via its prototype

let animal = {
  type: "Animal",
  describe() {
    return "I am a " + this.type;
  }
};

// dog inherits from animal via the prototype chain
let dog = Object.create(animal);
dog.type = "Dog";
dog.bark = function() { return "Woof!"; };

console.log(dog.describe()); // "I am a Dog"  (inherited from animal)
console.log(dog.bark());     // "Woof!"        (dog's own method)

// Confirm the prototype link
console.log(Object.getPrototypeOf(dog) === animal); // true

In JavaScript, functions are treated like any other value. You can store a function in a variable, pass it as an argument, or return it from another function. This is what "first-class functions" means.

This makes powerful patterns possible, like higher-order functions and closures. We'll explore both in detail in the functions tutorial.

javascript

// Define a function
function greet(name) {
  return "Hello, " + name + "!";
}

// Assign the function to a variable
var myFunction = greet;

// Call the function using the variable
var result = myFunction("John");

// Output the result
console.log(result);

In JavaScript, you don't have to declare what type a variable is. A variable can hold a number now and a string later. The type is determined while the program runs, not when you write the code. This is called dynamic typing.

In languages like Java or C, once you say a variable is a number, it's always a number. In JavaScript, the same variable can change types freely. This gives you flexibility, but it also means you need to be careful about unexpected type changes.

prototype

javascript

let x = 10; // type will be number 
x = "SimplyJavascript"; //type will be string 
x = false; //type will be boolean 

JavaScript is single-threaded, which means it does one thing at a time. It's like a single-lane road: only one car moves at any moment.

This is different from multi-threaded languages where multiple tasks run at the same time. But what happens when JavaScript gets a slow task? It uses Web Workers and asynchronous programming to handle heavy work in the background, so the main thread doesn't get blocked.

javascript

// Single-threaded: JavaScript does one thing at a time

console.log("Task 1: Start");

let total = 0;
for (let i = 1; i <= 5; i++) {
  total += i; // each step happens one at a time
}

console.log("Task 2: Sum =", total); // Sum = 15
console.log("Task 3: Done");

// Output is always in this exact order:
// Task 1: Start
// Task 2: Sum = 15
// Task 3: Done

Even though JavaScript is single-threaded, it doesn't freeze when it encounters a slow task (like fetching data from a server). This is thanks to the event loop.

The event loop works like a queue system. When a slow task comes in, JavaScript puts it aside and keeps running other code. When the slow task finishes, its result goes back into the queue, and the event loop picks it up. This is called "asynchronous programming", and it's what makes JavaScript feel fast and responsive.

javascript

// The event loop keeps JavaScript responsive during slow tasks

console.log("1 - Start");

// setTimeout schedules work for later ΓÇö does NOT block execution
setTimeout(function() {
  console.log("3 - Runs after a 2-second delay");
}, 2000);

console.log("2 - Runs immediately, doesn't wait for setTimeout");

// Output order:
// 1 - Start
// 2 - Runs immediately, doesn't wait for setTimeout
// 3 - Runs after a 2-second delay  (arrives 2 seconds later)

JavaScript runs in browsers, and browsers are available on almost every platform: Windows, macOS, Linux, Android, and iOS. That means the same JavaScript code can run across many devices with little or no change.

Platform Independent

javascript

// The same JavaScript code runs in every browser, on every OS

// Read runtime info about the user's browser and platform
console.log("Browser:", navigator.userAgent);

// Detect if the user is on a mobile device
let isMobile = /Mobi|Android/i.test(navigator.userAgent);
console.log("Mobile device?", isMobile);

// This works unchanged on:
// Chrome on Windows, Safari on iPhone,
// Firefox on Linux, Edge on Mac
  • High-level: Reads like English. No need to manage hardware details.
  • Garbage collected: Automatically frees unused memory for you.
  • Interpreted with JIT: Code runs line by line, but gets optimized into machine code on the fly for speed.
  • Multi-paradigm: Supports object-oriented, functional, and event-driven coding styles.
  • Prototype-based: Objects can inherit from other objects through a prototype chain.
  • First-class functions: Functions can be stored in variables, passed around, and returned like any other value.
  • Dynamically typed: Variables can change type at runtime. Flexible but requires care.
  • Single-threaded: Does one thing at a time, but uses async tools to avoid blocking.
  • Non-blocking event loop: Keeps the program responsive by handling slow tasks in the background.
  • Platform independent: Runs on any device with a browser.

What's next? Now that you know what makes JavaScript special, let's start writing actual code in the next tutorial.

lecture javascript
SimplyJavaScript Logo
Features In Javascript
lecture javascript
SimplyJavaScript Logo
Features In Javascript

Reviewed by

SimplyJavaScript Editorial Team

Technical editors and JavaScript educators with hands-on experience building frontend projects, writing learning material, and reviewing tutorials for clarity, accuracy, and beginner-friendly guidance.