JavaScript Data Types

Let's check the Data Types in JavaScript - Two Categories of Data Types:

  1. Primitive Data Types — These are immutable and cannot be modified after creation.

    a. String:

    let name = "JavaScript"; // typeof(name) — 'string'

    b. Number:

    let age = 18; // typeof(age) — number

    c. BigInt:

    console.log(9007199254740991n + 1n); // 9007199254740992n

    d. Boolean:

    let truth = false; // typeof(truth) — boolean

    e. null:

    let age = null; // null

    f. Undefined:

    let age; // undefined

    g. Symbol:

    let id = Symbol('id');

  2. Non-Primitive Data Types — These are mutable and can be modified after creation.

    a. Object:

    var student = { firstName: "Hello", lastName: "World", age: 18, height: 170, fullName: function() { return this.firstName + " " + this.lastName; } };

    b. Array:

    var colors = ["red", "green", "blue"];

    c. Function:

    function greet(name) { return "Hello, " + name + "!"; }

In addition to the primitive data types listed above, non-primitive data types include objects (like the 'student' example), arrays, and functions, which are mutable and can be modified after their initial creation. These non-primitive types provide flexibility in handling and manipulating data in more complex ways.

Comments

Popular posts from this blog

10 JS Interview Prep Coding Problems with solution

Exploring HTML5: New Features For Interview Prep