JavaScript Series — Phase 1 day 4 — JavaScript Fundamentals
1.📝 String
A String is used to store text.
Strings can be written using:
Single quotes ' ' Double quotes " " Backticks
Example:
let name = "Tuhin"; let city = 'Kolkata'; let message = Hello JavaScript!;
You can also check the type using:
console.log(typeof name);Output:
string
Where are Strings used?
Names
Messages
Email addresses
Addresses
Text content
User input
2. 🔢 Number
The Number data type is used for numerical values.
Example:
let age = 21;
let price = 99.99;
let temperature = -5;
JavaScript uses the same Number type for both integers and floating-point numbers.
console.log(typeof age);
Output:
number
You can perform mathematical operations:
let a = 10;
let b = 5;
console.log(a + b);
console.log(a - b);
console.log(a * b);
console.log(a / b);
3. ✅ Boolean
A Boolean can have only two values:
true
false
Example:
let isLoggedIn = true;
let isAdmin = false;
Boolean values are commonly used for conditions and decision-making.
For example:
let age = 20;
console.log(age >= 18);
Output:
true
Where are Booleans used?
Login status
User permissions
Conditions
Form validation
On/off states
4. ❓ Undefined
A variable has the value undefined when it has been declared but no value has been assigned to it.
Example:
let result;
console.log(result);
Output:
undefined
You can check its type:
console.log(typeof result);
Output:
undefined
Important point
undefined usually means:
A value has not been assigned yet.
4. ❓ Undefined
A variable has the value undefined when it has been declared but no value has been assigned to it.
Example:
let result;
console.log(result);
Output:
undefined
You can check its type:
console.log(typeof result);
Output:
undefined
Important point
undefined usually means:
A value has not been assigned yet.
5. 🚫 Null
null represents the intentional absence of a value.
Example:
let selectedUser = null;
console.log(selectedUser);
Output:
null
The important difference is:
undefined → No value has been assigned
null → We intentionally set the value to "nothing"
For example:
let user = null;
This can mean that there is currently no user selected.
A JavaScript quirk
typeof null
returns:
object
This is a well-known historical behavior in JavaScript
6. 🔢 BigInt
BigInt is used to represent integers larger than the maximum safe integer that JavaScript's Number type can reliably represent.
You create a BigInt by adding n at the end of an integer:
let bigNumber = 123456789012345678901234567890n;
console.log(bigNumber);
Check the type:
console.log(typeof bigNumber);
Output:
bigint
Important
You generally cannot directly mix BigInt and Number in arithmetic:
10n + 5
This causes an error.
Instead, use the same type:
10n + 5n
7. 🔑 Symbol
A Symbol creates a unique value.
Example:
let id = Symbol("id");
console.log(id);
Every Symbol is unique, even when the descriptions are the same:
let a = Symbol("id");
let b = Symbol("id");
console.log(a === b);
Output:
false
Where are Symbols useful?
They are commonly used as unique object property keys, especially when you want to avoid property-name collisions.
For beginners, remember:
Symbol represents a unique identifier.
8. 📦 Objects
An Object is used to store collections of related data.
Example:
let student = {
name: "Tuhin",
age: 21,
course: "Computer Science"
};
You can access the values:
console.log(student.name);
console.log(student.age);
Output:
Tuhin
21
Objects can contain different types of values:
let user = {
name: "Tuhin",
age: 21,
isLoggedIn: true
};
Here:
name → String
age → Number
isLoggedIn → Boolean
Objects are extremely important because they are used heavily in JavaScript applications, APIs, React, Node.js, and web development.
🧩 Primitive vs Non-Primitive Data Types
This is one of the most important concepts in Day 4.
Primitive Data Types
JavaScript has 7 primitive data types:
String
Number
BigInt
Boolean
Undefined
Null
Symbol
Primitive values represent individual values.
Example:
let name = "Tuhin"; let age = 21; let isStudent = true; Non-Primitive Data Types
The main non-primitive/reference type is:
Object
Objects can contain multiple values.
Example:
let student = { name: "Tuhin", age: 21, course: "Computer Science" };
Arrays and functions are also objects in JavaScript's type system.
Example:
let numbers = [10, 20, 30]; function greet() { console.log("Hello!"); } 📊 Primitive vs Non-Primitive Primitive Non-Primitive String Object Number Array Boolean Function Undefined Other object types Null BigInt Symbol Simple way to remember Primitive ↓ Single value
Non-Primitive ↓ Can represent complex/structured data
🔍 Checking Data Types with typeof
JavaScript provides the typeof operator to check a value's type.
console.log(typeof "Hello");
console.log(typeof 100);
console.log(typeof true);
console.log(typeof undefined);
console.log(typeof 100n);
Output:
string
number
boolean
undefined
bigint
For objects:
let student = {
name: "Tuhin"
};
console.log(typeof student);
Output:
object
Remember the special case:
console.log(typeof null);
Output:
object
This is a historical JavaScript quirk.
Comments
Join the discussionNo comments yet. Be the first to comment.