JavaScript Tokens: Basic building blocks
- compnomics
- Feb 22, 2024
- 1 min read

In JavaScript, tokens are the basic building blocks of the code that the interpreter understands and processes. These tokens are categorized into different types based on their function and meaning. Here's a list of the main JavaScript tokens:
Reserved Keywords:
These words have special meanings within the language and cannot be used as variable names or identifiers. Examples include var, let, const, if, else, for, while, function, return, etc.
Identifiers:
These are names given to variables, functions, classes, and other entities you define in your code. They must start with a letter or underscore (_), followed by letters, numbers, or underscores.
Literals:
These represent fixed values directly embedded in your code. Examples include:
Numbers: 123, 4.56, -100e2
Strings: "Hello, world!", 'This is a string', ${variableName} (template literals)
Booleans: true, false
Null: null
Undefined: undefined
Operators:
These perform various operations on values. Examples include:
Arithmetic: +, -, *, /, %
Comparison: ==, !=, ===, !==, <, >
Logical: &&, ||, !
Bitwise: &, |, ^, <<, >>
Assignment: =, +=, -=, *=, etc.
Punctuators:
These are special characters used for syntax and structure. Examples include:
Brackets: [], {}, ()
Commas: ,
Semicolons: ;
Quotes: ', "
Dots: ., .. (spread operator)
Arrows: -> (function definition)
Whitespace:
Spaces, tabs, and newlines are generally ignored by the interpreter but can be used for readability.
Comments:
Comments are lines of text ignored by the interpreter but used to explain your code and improve its clarity. They start with // for single-line comments or /* ... */ for multi-line comments.
Remember that this is a basic overview, and the specific list of tokens might vary depending on the JavaScript version and specific context.
Comments