Exercise

In JavaScript, data types define the type of data that can be stored and manipulated by variables. There are primitive data types and non-primitive data types.

The primitive data types in JavaScript are:

  • Number
  • String
  • Boolean
  • Null
  • Undefined
  • Symbol (added in ECMAScript 6)

In JavaScript, you can declare a number variable using the var, let, or const keywords.

javascript

var num = 10;
let anotherNum = 20;
const PI = 3.14;

null represents the intentional absence of any value, while undefined represents the absence of a value that has not been assigned.

In JavaScript, you can declare a string variable using single quotes (''), double quotes ("") or backticks (``).

javascript

var str1 = 'Hello';
var str2 = "World";
let str3 = `JavaScript`;

The boolean data type in JavaScript represents a value that is either true or false.

In JavaScript, you can declare a boolean variable by assigning the value true or false to it.

javascript

var isTrue = true;
let isFalse = false;

Undefined in JavaScript represents a variable that has been declared but has not been assigned a value.

Null in JavaScript represents the intentional absence of any value.

The typeof operator in JavaScript is used to determine the data type of a variable or an expression.