HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials
  • Insights
  • Verify Certificate
HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials
HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials

HTML5andCSS3.org helps developers learn modern frontend skills with practical tutorials, production-ready snippets, and fast web tools built for everyday coding.

Quick Links

  • About Us
  • Contact Us
  • Privacy Policy
  • Copyright
  • Disclaimer

Top Tools

  • Try It Editor
  • JSON Formatter
  • CSS Minifier
  • HTML Minifier
  • Base64 Encoder / Decoder

Contact

  • business@html5andcss3.org
Newsletter

Learn at your own pace, practice with useful tools, and build websites you're proud of.

© 2011-2026 html5andcss3.org. All rights reserved.

How to Use

JavaScript Tutorial

JavaScript Introduction

What is JavaScriptJavaScript FeaturesJavaScript SyntaxHow to Add JavaScriptJavaScript OutputJavaScript Comments

JavaScript Basics

JavaScript VariablesJavaScript Data TypesJavaScript Operators

JavaScript Statement & Expression

JavaScript StatementsJavaScript ExpressionsJavaScript KeywordsJavaScript IdentifiersJavaScript Case SensitivityJavaScript SemicolonsJavaScript Code Blocks

JavaScript Conditions

JavaScript if StatementJavaScript if else StatementJavaScript else if StatementJavaScript switch Statement

JavaScript Loops

JavaScript for LoopJavaScript while LoopJavaScript do while LoopJavaScript break Statement
  1. Home
  2. /
  3. Tutorials
  4. /
  5. JavaScript Tutorial
  6. /
  7. JavaScript Keywords

JavaScript Statement & Expression

JavaScript Keywords

JavaScript keywords are reserved words that have a special meaning in JavaScript.

These words are already used by JavaScript for specific tasks, so you cannot use them as variable names, function names, or object names.

Example

Example

javascript

let name = "Amit";

Here, let is a JavaScript keyword. It is used to declare a variable.

What are Keywords?

Keywords are special words that JavaScript understands.

Each keyword has a fixed purpose.

Example

javascript

if (age >= 18) {
  console.log("You are eligible.");
}

In this example:

KeywordUse
<code>if</code>Checks a condition

The word if has a special meaning in JavaScript, so it cannot be used as a variable name.

Common JavaScript Keywords

Here are some commonly used JavaScript keywords:

KeywordUse
<code>let</code>Declares a variable
<code>const</code>Declares a constant variable
<code>var</code>Declares a variable
<code>if</code>Starts a condition
<code>else</code>Runs code when condition is false
<code>switch</code>Checks multiple cases
<code>case</code>Defines a case inside switch
<code>break</code>Stops a loop or switch
<code>for</code>Starts a for loop
<code>while</code>Starts a while loop
<code>function</code>Defines a function
<code>return</code>Returns a value from a function
<code>class</code>Defines a class
<code>new</code>Creates a new object
<code>try</code>Tests a block of code
<code>catch</code>Handles errors
<code>import</code>Imports code from another file
<code>export</code>Exports code to another file

Keywords for Variables

JavaScript uses let, const, and var to declare variables.

Example

javascript

let userName = "Amit";
const country = "India";
var city = "Delhi";

In modern JavaScript, let and const are used more commonly than var.

Keywords for Conditions

JavaScript uses keywords like if, else, and switch for conditions.

Example

javascript

let age = 20;

if (age >= 18) {
  console.log("Adult");
} else {
  console.log("Minor");
}

Here, if checks the condition, and else runs when the condition is false.

Keywords for Loops

JavaScript uses keywords like for, while, and break with loops.

Example

javascript

for (let i = 1; i <= 3; i++) {
  console.log(i);
}

Here, for is used to repeat code.

The break keyword can stop a loop.

Example

javascript

for (let i = 1; i <= 5; i++) {
  if (i === 3) {
    break;
  }

  console.log(i);
}

Keywords for Functions

JavaScript uses function and return to create and use functions.

Example

javascript

function add(a, b) {
  return a + b;
}

let result = add(10, 20);

Here:

KeywordUse
<code>function</code>Creates a function
<code>return</code>Sends a value back from the function

Keywords Cannot Be Used as Names

You cannot use JavaScript keywords as variable names.

Wrong example:

Wrong Example

javascript

let if = "Hello";
let function = "Test";
let return = 100;

These names are not allowed because if, function, and return are reserved keywords.

Correct example:

Correct Example

javascript

let userStatus = "Hello";
let functionName = "Test";
let returnValue = 100;

Use meaningful names that are not JavaScript keywords.

Complete Example

Complete Example

html

<!DOCTYPE html>
<html>
<head>
  <title>JavaScript Keywords</title>
</head>
<body>

  <h1>JavaScript Keywords</h1>

  <p id="result"></p>

  <script>
    let age = 20;
    let message;

    if (age >= 18) {
      message = "You are eligible.";
    } else {
      message = "You are not eligible.";
    }

    document.getElementById("result").innerHTML = message;
  </script>

</body>
</html>

Try It Yourself

Run the above example in the Try It Editor.

Try changing the value of age and check how the result changes.

Also try using different keywords like const, function, and return.

Important Points

  • JavaScript keywords are reserved words.
  • Each keyword has a special meaning.
  • Keywords cannot be used as variable names.
  • Common keywords include let, const, if, else, for, while, function, and return.
  • Use meaningful names for variables and functions instead of reserved keywords.

Conclusion

JavaScript keywords are special reserved words used to perform specific tasks.

They help JavaScript create variables, check conditions, run loops, define functions, handle errors, and work with modules.

Understanding keywords is important because they are used in almost every JavaScript program.

PreviousJavaScript ExpressionsNextJavaScript Identifiers