top of page
Writer's picturecompnomics

JavaScript Tokens: Basic building blocks


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 varletconstifelseforwhilefunctionreturn, 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: 1234.56-100e2

  • Strings: "Hello, world!"'This is a string'${variableName} (template literals)

  • Booleans: truefalse

  • 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.

15 views0 comments

Recent Posts

See All

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page