Keyword

A keyword is a reserved word in JavaScript that has a special meaning and cannot be used as a variable, function, or label name. Keywords are fundamental to the language's syntax and structure.

Common JavaScript Keywords

Variable Declaration var, let, const

Control Flow if, else, switch, case, default

Loops for, while, do, break, continue

Functions function, return, async, await, yield

Object-Oriented class, extends, super, this, new

Error Handling try, catch, finally, throw

Module System import, export, from, as

Other typeof, instanceof, in, delete, void

Reserved for Future Use

enum, implements, interface, package, private, protected, public, static

Examples

javascript
// Variable keywords
const PI = 3.14159
let counter = 0
var legacy = 'old style'

// Control flow
if (condition) {
  // do something
} else {
  // do something else
}

// Function keywords
async function fetchData() {
  try {
    const response = await fetch(url)
    return response.json()
  } catch (error) {
    throw new Error('Failed to fetch')
  }
}

// Class keywords
class Animal extends LivingThing {
  constructor(name) {
    super()
    this.name = name
  }
}

Best Practice

Avoid using keywords as identifiers to prevent syntax errors and maintain code clarity.