Skip to content

Latest commit

 

History

History
72 lines (56 loc) · 2.1 KB

File metadata and controls

72 lines (56 loc) · 2.1 KB

Data Types In Javascript

Data types in Js are similar to other programming languages (C# or Java). Javascript minimizes the need to specify the type of variable. The following example shows how a variable can be assigned any type of value.

var testVariable = 1;  // numeric value

testVariable = 'one'; // string value

testVariable = 1.1; // decimal value

testVariable = true; // Boolean value

testVariable = null; // null value

JavaScript includes primitive and non-primitive data types as per latest ECMAScript 5.1.



1. Primitive Data Types

These are the lowest level of the data value in JavaScript. The typeof operator can be used with primitive data types to know the type of a value.

Examples :

  • String : String is a textual content wrapped inside ' ' or " " or (tick sign).

  • Number : Number is a numeric value. Example: 100, 4521983, etc.

  • BigInt : BigInt is a numeric value in the arbitrary precision format. Example: 453889879865131n, 200n, etc.

  • Boolean : Boolean is a logical data type that has only two values, true or false. Null : A null value denotes an absense of value. Example: var str = null;

  • Undefined : undefined is the default value of a variable that has not been assigned any value.



2. Non Primitive Data Types

  • Object: An object holds multiple values in terms of properties and methods.
Example:
            var person = { 
                firstName: "James", 
                lastName: "Bond", 
                age: 15
            }; 
  • Date: Date object represents date & time including days, months, years, hours, minutes, seconds and milliseconds.
Example: 
            var today = new Date("25 July 2021");
  • Array : An array stores multiple values using special syntax.
Example: 
            var nums = [1, 2, 3, 4];

For Detailed Descriptions visit the following Links: