Labs ICT
🎓 SIWES/IT Login

Data Types

1 min read | JavaScript Tutorial
🎓

Doing SIWES / IT attachment?

Get a structured training programme, a supervised digital logbook, and a completion certificate with LabsICT SIWES / IT.

Explore SIWES / IT Training

JavaScript Data Types

JavaScript has seven primitive data types and one complex type (Object). Primitives are immutable — once created, they can't be changed. Objects are collections of key-value pairs.

The primitives: String, Number, Boolean, null, undefined, Symbol, and BigInt.

String

let greeting = "Hello";
let name = 'Alice';
let template = `Hello, ${name}!`;
console.log(template);

Number

let integer = 42;
let float = 3.14;
let negative = -10;
console.log(integer, float, negative);

Boolean

let isActive = true;
let isComplete = false;
console.log(isActive, isComplete);

Object

let user = {
  firstName: "Alice",
  age: 30,
  isAdmin: false
};
console.log(user.firstName);

Array

let fruits = ["apple", "banana", "cherry"];
console.log(fruits[0]);
console.log(fruits.length);

null and undefined

let empty = null;
let notDefined;
console.log(empty);
console.log(notDefined);

typeof Operator

console.log(typeof "hello");
console.log(typeof 42);
console.log(typeof true);
console.log(typeof {});
console.log(typeof null); // "object" — a known quirk!

Dynamic Typing

let value = "Hello";
console.log(typeof value);
value = 42;
console.log(typeof value);
value = true;
console.log(typeof value);

Type Coercion in Action

console.log("5" - 3);
console.log("5" + 3);
console.log(5 + "3");
console.log("5" * "3");