JavaScript Language Reference

Table of Contents

Introduction to JavaScript

JavaScript is a dynamic, weakly-typed, prototype-based, multi-paradigm programming language. It is most commonly used as a scripting language for web pages, but it is also used in many non-browser environments such as Node.js, server-side applications, and mobile apps.

This section provides a comprehensive reference to the core language features of JavaScript, covering syntax, semantics, and standard library objects.

Core Concepts

Understanding the fundamental building blocks of JavaScript is crucial for effective development.

Variables

Variables are containers for storing data values. In JavaScript, you declare variables using var, let, or const.

let message = "Hello, World!";
const PI = 3.14159;
var count = 10;

Data Types

JavaScript has several primitive data types and the object type:

Operators

Operators are special symbols that perform operations on values and variables.

Common Operators

  • Arithmetic: +, -, *, /, %
  • Assignment: =, +=, -=, etc.
  • Comparison: ==, ===, !=, !==, >, <, etc.
  • Logical: &&, ||, !
  • Bitwise: &, |, ^, ~, <<, >>
  • Type: typeof, instanceof

Control Flow

Control flow statements determine the order in which code statements are executed.

Functions

Functions are blocks of reusable code designed to perform a particular task.

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

const greetArrow = (name) => `Hello, ${name}!`;

console.log(greet("Alice"));
console.log(greetArrow("Bob"));

Objects

Objects are collections of properties, where each property is a key-value pair. Keys are usually strings.

const person = {
  firstName: "John",
  lastName: "Doe",
  age: 30,
  fullName: function() {
    return this.firstName + " " + this.lastName;
  }
};

console.log(person.firstName);
console.log(person.fullName());

Arrays

Arrays are special variables that can hold more than one value in a single variable. They are a type of object.

const fruits = ["Apple", "Banana", "Cherry"];

console.log(fruits[0]); // "Apple"
fruits.push("Date");
console.log(fruits.length); // 4

Classes

Classes are blueprints for creating objects. They were introduced in ECMAScript 2015 (ES6) as syntactic sugar over JavaScript's existing prototype-based inheritance.

class Animal {
  constructor(name) {
    this.name = name;
  }

  speak() {
    console.log(`${this.name} makes a noise.`);
  }
}

class Dog extends Animal {
  speak() {
    console.log(`${this.name} barks.`);
  }
}

const dog = new Dog("Buddy");
dog.speak(); // Buddy barks.

Built-in Objects

JavaScript provides a rich set of built-in objects that offer predefined properties and methods for common tasks.

Refer to the Built-in Objects section for detailed documentation on each object.

Advanced Topics

Explore more advanced features and patterns in JavaScript:

Dive into specific topics through the sidebar navigation for a deeper understanding.