# 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:

> > *<s>l</s>*`et 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:

```plaintext
let age = 21;
let price = 99.99;
let temperature = -5;
```

JavaScript uses the same `Number` type for both integers and floating-point numbers.

```plaintext
console.log(typeof age);
```

Output:

```plaintext
number
```

You can perform mathematical operations:

```plaintext
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:

```plaintext
true
false
```

Example:

```plaintext
let isLoggedIn = true;
let isAdmin = false;
```

Boolean values are commonly used for **conditions and decision-making**.

For example:

```plaintext
let age = 20;

console.log(age >= 18);
```

Output:

```plaintext
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:

```plaintext
let result;

console.log(result);
```

Output:

```plaintext
undefined
```

You can check its type:

```plaintext
console.log(typeof result);
```

Output:

```plaintext
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:

```plaintext
let result;

console.log(result);
```

Output:

```plaintext
undefined
```

You can check its type:

```plaintext
console.log(typeof result);
```

Output:

```plaintext
undefined
```

### Important point

`undefined` usually means:

> **A value has not been assigned yet.**

## **5\. 🚫 Null**

`null` represents the **intentional absence of a value**.

Example:

```plaintext
let selectedUser = null;

console.log(selectedUser);
```

Output:

```plaintext
null
```

The important difference is:

```plaintext
undefined → No value has been assigned
null      → We intentionally set the value to "nothing"
```

For example:

```plaintext
let user = null;
```

This can mean that there is currently **no user selected**.

### A JavaScript quirk

```plaintext
typeof null
```

returns:

```plaintext
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:

```plaintext
let bigNumber = 123456789012345678901234567890n;

console.log(bigNumber);
```

Check the type:

```plaintext
console.log(typeof bigNumber);
```

Output:

```plaintext
bigint
```

### Important

You generally cannot directly mix `BigInt` and `Number` in arithmetic:

```plaintext
10n + 5
```

This causes an error.

Instead, use the same type:

```plaintext
10n + 5n
```

## **7\. 🔑 Symbol**

A **Symbol** creates a unique value.

Example:

```plaintext
let id = Symbol("id");

console.log(id);
```

Every Symbol is unique, even when the descriptions are the same:

```plaintext
let a = Symbol("id");
let b = Symbol("id");

console.log(a === b);
```

Output:

```plaintext
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:

```plaintext
let student = {
    name: "Tuhin",
    age: 21,
    course: "Computer Science"
};
```

You can access the values:

```plaintext
console.log(student.name);
console.log(student.age);
```

Output:

```plaintext
Tuhin
21
```

Objects can contain different types of values:

```plaintext
let user = {
    name: "Tuhin",
    age: 21,
    isLoggedIn: true
};
```

Here:

```plaintext
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:

1.  String
    
2.  Number
    
3.  BigInt
    
4.  Boolean
    
5.  Undefined
    
6.  Null
    
7.  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.

```plaintext
console.log(typeof "Hello");
console.log(typeof 100);
console.log(typeof true);
console.log(typeof undefined);
console.log(typeof 100n);
```

Output:

```plaintext
string
number
boolean
undefined
bigint
```

For objects:

```plaintext
let student = {
    name: "Tuhin"
};

console.log(typeof student);
```

Output:

```plaintext
object
```

Remember the special case:

```plaintext
console.log(typeof null);
```

Output:

```plaintext
object
```

This is a historical JavaScript quirk.
