What are the Tokens in Javascript with Examples

Tokens in Javascript

In this article, we will see about tokens of javascript.

What are tokens

The smallest unit of any programming language is called a Token. Every Javascript statements and expression is created using tokens. We can very easily remember tokens of javascript language by remembering the shortcut “C-KICS-OS”. which means

  • C- Comments
  • K – Keywords & Data types
  • I – Identifiers
  • C – Constant & Variables
  • S- String & Character
  • O – Operators
  • S – Separators

Examples

Comments

We can use comments in Javascript using double hash “//”.

// declaring variable
var a= 10;
document.write(a);
// output : 10

Keywords & Data types

In Javascript, there are a lot of keywords ‘for’, ‘while’, true, etc. And also lot of data types like ‘var’, ‘const’, etc.

const stud = "Raj";
document.write(stud);
// output : Raj

Identifiers

It means variable names. For the below, example the student is identifiers

const student = "Raj";
document.write(student);
// output : Raj

Constant & Variables

We can use the ‘const’ keyword to create a constant and use the ‘var’ keyword to create a variable in javascript. Here, example we create both variable and constant. The difference between constant and variable is we can change the value of variables but we cannot change the value of constant.

const student = "Raj";
student = "Raju";
var mark= 10;
mark= 0;
document.write(mark);
document.write(student);
/*
output:
10
Raj
*/

String & Character

// name is string
const name = "Ram";
// printing first letter in string
document.write(name[0]);
// output : R

Operators

There are many operators in Javascript. Here we use the arithmetic addition operator.

var a = 10;
var b =5;
document.write(a+b);
// output : 15

Leave a Reply