Javascript Basic Data Types

Nabed Khan
2 min readNov 3, 2020

--

We can need to define the variable in any programming language. As a beginner, we don’t know about which type of data we define with a variable. So, at first, we need to know about the data type. Today we discuss javascript data types. Basically, Javascript has two types of data types:

  1. Primitive Data Types
  2. Non-Primitive/Reference Data Types

typeof Operator:

It helps us to check which type of data we are defined. Check an example below:

var name = 'Nabed';
console.log(typeof name);
Output is: string

Our result is the string because we declare a string value. So, Let’s discuss javascript data.

Primitive Data Types:

  1. Number
  2. String
  3. Boolean
  4. Null
  5. Undefined

Number Data Type:

When we declare a variable with a numeric value. it’s called number data type. we can also use the floating number.

var age = 24;
var price = 49.99;

String Data Type:

A string data type one or more character within the quotation. when we declare string we need to use double quotation(“ ”) or single quotation (‘ ’).

var name = 'Nabed Khan';

Boolean Data Type:

Boolean data type provides us two values. true either false.

var value = true;
var value2 = false;
console.log(typeof value);
console.log(typeof value2);
Output is:
boolean
boolean

Null Data Type:

Null data type represented by empty, nothing, or unknown value. we need to write it in small letter.

var value = null;

Undefined Data Type:

The undefined mean value isn’t defined. Most of the time we didn’t assign a value with a variable. It’s called undefined value

var value
console.log(value);
Output is: undefined

Non-Primitive/Reference Data Types:

  1. Object

Object Data Type:

The object data type used for the complex data structure. there are have a collection of properties and methods.

var person ={
name: 'Alex Smith',
age: 20,
profession: 'student',
address: 'New York, USA'
}

--

--