JavaScript: Data Types JavaScript

JavaScript Data Types

Data Types in JavaScript

Many data types can be held in JavaScript variables like Numbers, Strings, Objects etc. There are many such programming languages in which you have to declare a variable of the same data type as the value you want to store in the variable, but in JavaScript it is not like this. No, in JavaScript you can store the value of every type of data type in the same variable. There are two types of data types in JavaScript.

Primitive Data Type

There are five types of primitive data types in JavaScript which are as follows:

i. String data type

String represents a sequence of characters such as “New”, “hello”. String data type should be written within double quotation mark (” “).

Example:

    <code>
    "python", "grade", "123.67", "###"
    </code>
  

ii. Number data type

Number represents numeric values.

Example:

    <code>
    234, 73.3, -15.80
    </code>
  

iii. Boolean

Boolean represents the values whether these values are False or True.

iv. Undefined

It represents undefined values.

v. Null

Represents Null Values and checks that there is no value.

Non-primitive data types

Non-primitive data types are as follows:

i. Object

Object represents an instance through which we can use numbers.

Example:

    <code>
    let person = {
      name: "John",
      age: 30,
      isStudent: false
    };
    </code>
  

ii. Array

Array is used to represent values of similar type. The array index starts from 0, so that the first array element is arr[0], arr[1].

Example:

    <code>
    let colors = ["red", "green", "blue"];
    let numbers = [1, 2, 3, 4.5];
    </code>
  

iii. RegExp

RegExp represents a regular expression.

Example:

    <code>
    let pattern = /hello/i;  // Regular expression to match "hello"
    </code>
  
Next Post Previous Post