Skip to content

Commit c6a4acd

Browse files
feat: add updated non_primitives.js file
1 parent cd811c8 commit c6a4acd

File tree

3 files changed

+40
-65
lines changed

3 files changed

+40
-65
lines changed

part2 (Data Types and Primitives)/01_non_primitives.js

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Non-Primitive Data Types in JavaScript
2+
// These are reference types — stored and compared by reference (memory address).
3+
4+
// 1. Object
5+
const user = {
6+
name: "Rafay",
7+
age: 22,
8+
isAdmin: false
9+
};
10+
11+
console.log(typeof user); // "object"
12+
console.log(user.name); // "Rafay"
13+
14+
// 2. Array (special type of object)
15+
const skills = ["HTML", "CSS", "JavaScript"];
16+
17+
console.log(typeof skills); // "object"
18+
console.log(skills[1]); // "CSS"
19+
20+
// 3. Function (also a type of object)
21+
function greet(name) {
22+
return `Hello, ${name}!`;
23+
}
24+
25+
console.log(typeof greet); // "function"
26+
console.log(greet("Rafay")); // "Hello, Rafay!"
27+
28+
// 4. Date (built-in object)
29+
const today = new Date();
30+
31+
console.log(typeof today); // "object"
32+
console.log(today.toDateString()); // e.g., "Wed Jun 11 2025"
33+
34+
// 5. Object Comparison (by reference)
35+
const obj1 = { a: 1 };
36+
const obj2 = { a: 1 };
37+
const obj3 = obj1;
38+
39+
console.log(obj1 === obj2); // false (different memory)
40+
console.log(obj1 === obj3); // true (same reference)

part2 (Data Types and Primitives)/02_primitives.js

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)