learning JavaScript

learning JavaScript

Data Types in JavaScript

Table of contents

No heading

No headings in the article.

What are Data Types? A data type is an attribute associated with a piece of data that tells a computer how to interpret its value. In other words, it is information used to identify data stored in a variable.There are 6 Data types in JavaScript which include numbers, strings, booleans, objects, null and undefined.

  1. Numbers

    A number is an integer that can be positive or negative, floating-point, exponential value.

    Ex.

    var = -5; //negative integer

    var a = 5; //positive integer

    var c = 5.5; //floating point

  2. Strings

    A String is a group of characters enclosed with single/ double quotes or back ticks ( ' , " , ` ).

    Ex.

    var str1 = "Hello JavaScript"

    var str2 = 'Hello JavaScript'

  3. Booleans

    A boolean is a logical data type to compare two values or condition if they are true or false.

    Ex.

    var a = 10;

    var b = 7;

    a==b //returns false

  4. Objects

    In an object, we can store a collection of information inside an entry.

    Ex.

    var person1 = {

    first_name: "Jon",

    last_name: "Doe",

    age: 25

    }

  5. null

    Null Is a value data type that can be used when we want to intentionally leave as an empty value when it run.

    Ex.

    Var a = null;

  6. Undefined

    An undefined data type is any variable in which does not have a value. In other words, it is declared but not assigned with any value.

    Ex.

    var a;

Reference:

Flatiron frontend course work

shiksha.com/online-courses/articles/javascr..