Javascript Data types

Data types in javascript

Data types in javascript

We have 8 basic data types in javascript.

  1. number for numbers of any kind: integer or floating-point, integers are limited by ±253.
  2. bigint is for integer numbers of arbitrary length.
  3. string for strings. A string may have zero or more characters, there’s no separate single-character type.
  4. boolean for true/false.
  5. null for unknown values – a standalone type that has a single value null.
  6. undefined for unassigned values – a standalone type that has a single value undefined.
  7. object for more complex data structures.
  8. symbol for unique identifiers.

Number

  • It represents both integers and float numbers
  • Besides regular numbers, there are so-called "special numeric values" which also belong to this data type: Infinity, -Infinity and NaN.

Example:

let num1;
nmu1 = 100;
let num2 = 200.55;
let inf = 1/0; // Infinity
let negInf = -1/0; // -Infinity
let nan = "hi"/0; // NaN

BigInt

In JavaScript, the "number" type cannot represent integer values larger than (253-1) (that’s 9007199254740991), or less than -(-253-1) for negatives. It’s a technical limitation caused by their internal representation.

const bigInt = 345347890123456789012345678901234567890n;

String

  • A string in javascript is mutable collection of characters.
  • A string in javaScript must be surrounded by quotes.
let name = "Jim"
let title = "You can do anything"

Boolean

  • A boolean is a data type which is used to represent the values true or false

Example

let isValid = true;
let isChecked = false;
let isBig = 100 > 50000

null

  • It's a special value in javascript which represents nil value
  • It's not type

Example

let title = null;

undefined

  • undefined is also a special value in javascript just like null which tells that value is not assigned.

Example

let name;

Object

  • The Object class represents one of JavaScript's data types. It is used to store various keyed collections and more complex entities.

Example

let student_info = {
    name: "Jess",
    age: 20,
}

Symbol

  • A symbol represents a unique identifier
let id = Symbol("id");