javascript

Reserved Keywords


 

In JavaScript, reserved keywords are specific words that hold predefined meanings and cannot be used as identifiers (such as variable or function names) in the code. These keywords are fundamental to the language's syntax and have special purposes.

 

 

abstract

arguments

boolean

break

byte

case

catch

char

const

continue

debugger

default

delete

do

double

else

eval

false

final

finally

float

for

function

goto

if

implements

in

instanceof

int

interface

long

native

new

null

package

private

protected

public

return

short

static

switch

synchronized

this

throw

throws

transient

true

try

typeof

var

void

volatile

while

with

yield

 

 

 

 

 

abstract

Description: A keyword reserved for future use. 

This is a reserved keyword and is not used in JavaScript currently.

 

arguments

Description: An array-like object accessible inside functions that contains the values of the arguments passed to that function.

Example:

function sum() {
  let total = 0;
  for (let i = 0; i < arguments.length; i++) {
    total += arguments[i];
  }
  return total;
}
console.log(sum(1, 2, 3)); // Output: 6

 

boolean

Description: Represents a logical entity and can have two values: true or false.

Example:

let isRaining = true;
console.log(isRaining); // Output: true

 

break

Description: Terminates the current loop, switch, or label statement.

Example:

for (let i = 0; i < 10; i++) {
  if (i === 5) {
    break;
  }
  console.log(i); // Output: 0, 1, 2, 3, 4
}

 

byte

Description: A keyword reserved for future use.

Example:

// This is a reserved keyword and is not used in JavaScript currently.

 

case

Description: Defines a case in a switch statement.

Example:

let fruit = 'apple';
switch (fruit) {
  case 'apple':
    console.log('Apple');
    break;
  case 'banana':
    console.log('Banana');
    break;
  default:
    console.log('Unknown fruit');
}

 

catch

Description: Handles exceptions in a try block.

Example:

try {
  let result = someUndefinedFunction();
} catch (error) {
  console.log('An error occurred:', error.message);
}

 

char

Description: A keyword reserved for future use.

Example:

// This is a reserved keyword and is not used in JavaScript currently.

 

const

Description: Declares a block-scoped, read-only named constant.

Example:

const PI = 3.14;
console.log(PI); // Output: 3.14

 

continue

Description: Skips the rest of the current loop iteration and proceeds with the next iteration.

Example:

for (let i = 0; i < 10; i++) {
  if (i % 2 === 0) {
    continue;
  }
  console.log(i); // Output: 1, 3, 5, 7, 9
}

 

debugger

Description: Invokes any available debugging functionality.

Example:

let a = 5;
debugger; // The code execution will pause here if debugging is enabled.
let b = 10;
console.log(a + b); // Output: 15

 

default

Description: Specifies the default case in a switch statement.

Example:

let color = 'purple';
switch (color) {
  case 'red':
    console.log('Red');
    break;
  case 'blue':
    console.log('Blue');
    break;
  default:
    console.log('Unknown color');
}

 

delete

Description: Deletes a property from an object.

Example:

let car = { make: 'Toyota', model: 'Corolla' };
delete car.model;
console.log(car); // Output: { make: 'Toyota' }

 

do

Description: Executes a block of code at least once before checking the condition at the end of the loop.

Example:

let i = 0;
do {
  console.log(i); // Output: 0
  i++;
} while (i < 1);

 

double

Description: A keyword reserved for future use.

Example:

// This is a reserved keyword and is not used in JavaScript currently.

 

else

Description: Specifies the block of code to execute if the condition in an if statement is false.

Example:

let age = 18;
if (age >= 21) {
  console.log('You can drink.');
} else {
  console.log('You are too young to drink.');
}

 

eval

Description: Evaluates JavaScript code represented as a string.

Example:

let code = '2 + 2';
console.log(eval(code)); // Output: 4

 

false

Description: Represents the boolean value false.

Example:

let isWeekend = false;
console.log(isWeekend); // Output: false

 

final

Description: A keyword reserved for future use.

Example:

// This is a reserved keyword and is not used in JavaScript currently.

 

finally

Description: Executes a block of code after the try and catch blocks have executed.

Example:

try {
  let result = someUndefinedFunction();
} catch (error) {
  console.log('An error occurred:', error.message);
} finally {
  console.log('Execution completed.');
}

 

float

Description: A keyword reserved for future use.

Example:

// This is a reserved keyword and is not used in JavaScript currently.

for

Description: Creates a loop that is executed as long as the condition is true.

Example:

for (let i = 0; i < 5; i++) {
  console.log(i); // Output: 0, 1, 2, 3, 4
}

 

function

Description: Declares a function.

Example:

function greet(name) {
  console.log('Hello, ' + name);
}
greet('Alice'); // Output: Hello, Alice

 

goto

Description: A keyword reserved for future use.

Example:

// This is a reserved keyword and is not used in JavaScript currently.

 

if

Description: Executes a block of code if a specified condition is true.

Example:

let age = 18;
if (age >= 18) {
  console.log('You are an adult.');
}

 

implements

Description: A keyword reserved for future use.

Example:

// This is a reserved keyword and is not used in JavaScript currently.

 

in

Description: Checks if a property exists in an object.

Example:

let car = { make: 'Toyota', model: 'Corolla' };
console.log('make' in car); // Output: true

 

instanceof

Description: Tests whether an object is an instance of a specific constructor.

Example:

let date = new Date();
console.log(date instanceof Date); // Output: true

 

int

Description: A keyword reserved for future use.

Example:

// This is a reserved keyword and is not used in JavaScript currently.

 

interface

Description: A keyword reserved for future use.

Example:

// This is a reserved keyword and is not used in JavaScript currently.

long

Description: A keyword reserved for future use.

Example:

// This is a reserved keyword and is not used in JavaScript currently.

 

native

Description: A keyword reserved for future use.

Example:

// This is a reserved keyword and is not used in JavaScript currently.

 

new

Description: Creates an instance of an object.

Example:

let date = new Date();
console.log(date); // Output: current date and time

 

null

Description: Represents the intentional absence of any object value.

Example:

let value = null;
console.log(value); // Output: null

 

package

Description: A keyword reserved for future use.

Example:

// This is a reserved keyword and is not used in JavaScript currently.

 

private

Description: A keyword reserved for future use.

Example:

// This is a reserved keyword and is not used in JavaScript currently.

 

protected

Description: A keyword reserved for future use.

Example:

// This is a reserved keyword and is not used in JavaScript currently.

 

public

Description: A keyword reserved for future use.

Example:

// This is a reserved keyword and is not used in JavaScript currently.

 

return

Description: Exits a function and optionally returns a value.

Example:

function sum(a, b) {
  return a + b;
}
console.log(sum(2, 3)); // Output: 5

 

short

Description: A keyword reserved for future use.

Example:

// This is a reserved keyword and is not used in JavaScript currently.

 

static

Description: A keyword reserved for future use.

Example:

// This is a reserved keyword and is not used in JavaScript currently.

 

switch

Description: Evaluates an expression and matches the expression's value to a case clause.

Example:

let day = 2;
switch (day) {
  case 1:
    console.log('Monday');
    break;
  case 2:
    console.log('Tuesday');
    break;
  default:
    console.log('Another day');
}

 

synchronized

Description: A keyword reserved for future use.

Example:

// This is a reserved keyword and is not used in JavaScript currently.

 

this

Description: Refers to the current context or object.

Example:

let car = {
  make: 'Toyota',
  model: 'Corolla',
  display: function() {
    console.log(this.make + ' ' + this.model);
  }
};
car.display(); // Output: Toyota Corolla

 

throw

Description: Throws an exception.

Example:

function checkAge(age) {
  if (age < 18) {
    throw new Error('Underage');
  }
  return 'Adult';
}
try {
  console.log(checkAge(16));
} catch (error) {
  console.log(error.message); // Output: Underage
}

 

throws

Description: A keyword reserved for future use.

Example:

// This is a reserved keyword and is not used in JavaScript currently.

 

transient

Description: A keyword reserved for future use.

Example:

// This is a reserved keyword and is not used in JavaScript currently.

 

true

Description: Represents the boolean value true.

Example:

let isSunny = true;
console.log(isSunny); // Output: true

 

try

Description: Implements error handling by wrapping code that might throw an error.

Example:

try {
  let result = someUndefinedFunction();
} catch (error) {
  console.log('An error occurred:', error.message);
}

 

typeof

Description: Returns a string indicating the type of the unevaluated operand.

Example:

console.log(typeof 42); // Output: number
console.log(typeof 'Hello'); // Output: string

 

var

Description: Declares a variable, optionally initializing it to a value.

Example:

var name = 'Alice';
console.log(name); // Output: Alice

 

void

Description: Specifies that an expression does not return a value.

Example:

function logMessage() {
  console.log('This is a message.');
}
console.log(void logMessage()); // Output: undefined

 

volatile

Description: A keyword reserved for future use.

Example:

// This is a reserved keyword and is not used in JavaScript currently.

 

while

Description: Creates a loop that executes as long as a specified condition is true.

Example:

let i = 0;
while (i < 5) {
  console.log(i);
  i++;
}
// Output: 0, 1, 2, 3, 4

 

with

Description: Extends the scope chain for a statement.

Example:

let car = { make: 'Toyota', model: 'Corolla' };
with (car) {
  console.log(make);  // Output: Toyota
  console.log(model); // Output: Corolla
}

 

yield

Description: Pauses and resumes a generator function.

Example:

function* generator() {
  yield 1;
  yield 2;
  yield 3;
}
let gen = generator();
console.log(gen.next().value); // Output: 1
console.log(gen.next().value); // Output: 2
console.log(gen.next().value); // Output: 3

 

Reserved Keywords Added in ECMAScript 6, 2015:

 

await

class

enum

export

extends

import

let

super

 

 

await

Used inside an async function to wait for a promise to resolve.

async function fetchData() {
  let response = await fetch('https://api.example.com/data');
  let data = await response.json();
  console.log(data);
}
fetchData(); // Fetches data from the API and logs it once resolved.

 

class

Defines a blueprint for creating objects with specific properties and methods.

class Car {
  constructor(make, model) {
    this.make = make;
    this.model = model;
  }

  display() {
    console.log(this.make + ' ' + this.model);
  }
}

let myCar = new Car('Toyota', 'Corolla');
myCar.display(); // Output: Toyota Corolla

 

enum

This keyword is reserved for future use in JavaScript.

// This is a reserved keyword and is not used in JavaScript currently.

 

export

Used to export functions, objects, or primitive values from a module so they can be used in other modules.

export function greet(name) {
  return 'Hello, ' + name;
}
// This function can be imported in another module.

 

extends

Used in class declarations to create a class that is a child of another class.

class Vehicle {
  constructor(make) {
    this.make = make;
  }

  displayMake() {
    console.log(this.make);
  }
}

class Car extends Vehicle {
  constructor(make, model) {
    super(make);
    this.model = model;
  }

  display() {
    console.log(this.make + ' ' + this.model);
  }
}

let myCar = new Car('Toyota', 'Corolla');
myCar.display(); // Output: Toyota Corolla

 

import

Used to import functions, objects, or primitives that have been exported from an external module.

import { greet } from './greetings.js';
console.log(greet('Alice')); // Output: Hello, Alice

 

let

Declares a block-scoped variable, optionally initializing it to a value.

let name = 'Alice';
console.log(name); // Output: Alice

 

super

Calls the constructor or methods of the parent class.

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

  speak() {
    console.log(this.name + ' makes a noise.');
  }
}

class Dog extends Animal {
  constructor(name) {
    super(name);
  }

  speak() {
    super.speak();
    console.log(this.name + ' barks.');
  }
}

let dog = new Dog('Rex');
dog.speak();
// Output:
// Rex makes a noise.
// Rex barks.