Amrith Vengalath

Data Types and variables in Javascript

· Amrith Vengalath

Data Types

  • Undefined
  • Null
  • Boolean
  • String
  • Symbol
  • Number
  • Object

Undefined

Undefined in Javascript is something that hasn’t been defined. eg. A variable you haven’t set to anything yet

var x;
console.log(x);

output:

undefined

Null

Null means nothing. You set a variable to be something but the value is nothing

var x = null;
console.log(x);

output:

null

Boolean

A boolean means true or false

var x = 1>2;
console.log(x);

output:

false

String

String is just any sort of text.

var x = 'Hello World';
// 'here data type of x is string'

Symbol

Symbol is immutable and unique value.

let value = Symbol('hello');

Number

A Number is an integer or a floating-point number.

let x = 5;

Object

Object can store a lot of key value pairs of collection of data.

let person = {
firstName:"Jane",
lastName:"Doe",
age:20,
eyeColor:"blue"
};

When you assign a data to a variable the datatype of that variable becomes the datatype of that data you assigned.