JavaScript: Data Types

Primitive Values

A primitive is data that is not an object and has no methods.

All primitives are immutable/unchangeable.

5 Types of primitive values:

Number

// Integer
const age = 20;

// Float or Decimal
const price = 10.99;

String

const name = 'Yap';

Boolean

const isMale = true;
const hasRegistered = false;

Null

const favouriteVegetables = null;

Undefined

let loggedInUsers;

console.log(loggedInUsers); // output: undefined



Objects

Objects are non-primitive values.

Types of objects in JavaScript:

1) Array

const nums = [1, 2, 3];

2) Object

const user = {
    name: 'Yap',
    age: 20,
};

3) Function

function sayHello() {
    console.log('Hello');
}