Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Objects/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>
Object Destructuring, Object Referencing, Spread and Rest Operators,
Shallow vs Deep Copy
</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>
Object Destructuring, Object Referencing, Spread and Rest Operators,
Shallow vs Deep Copy
</h1>
<script src="script.js"></script>
<script src="interview.js"></script>
</body>
</html>
161 changes: 161 additions & 0 deletions Objects/interview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@


// Question 1 - What is the output

/*const obj = {
a: "one",
b: "two",
a: "three"
}

console.log(obj); */

/* ------------------------------------------------------------------------------------------------------------------------------------ */


// Question - 2 => Create a Function multiplyByTwo(obj) that multiplies all numeric property values of nums by 2.


/*let nums = {
a: 100,
b: 200,
title: "My Nums",
}


multiplyByTwo(nums)

function multiplyByTwo(obj) {
for (key in obj) {
if (typeof obj[key] === "number") {
obj[key] *= 2;
}
}
}

console.log(nums); */


/* ------------------------------------------------------------------------------------------------------------------------------------ */

// Question - 3 => What is the output of following code

/* const a = {}
const b = {key: "b"}
const c = { key: "c" }

a[b] = 123;
a[c] = 456;

console.log(a[b]); */


/* ------------------------------------------------------------------------------------------------------------------------------------ */

// Question - 4 => What is JSON.stringify and JSON.parse?

/* const user = {
name: "Bhavya",
age: 24
}

const strObj = JSON.stringify(user);

console.log(strObj);

localStorage.setItem("test", strObj)

console.log(JSON.parse(strObj)); */



/* ------------------------------------------------------------------------------------------------------------------------------------ */

// Question - 5 => What is the output?

// console.log([..."Alwar"]);


/* ------------------------------------------------------------------------------------------------------------------------------------ */

// Question - 6 => What is the output?

/*const user = { name: "Bhavya", age: 24 };
const admin = { admin: true, ...user }


console.log(admin); */


/* ------------------------------------------------------------------------------------------------------------------------------------ */

// Question - 7 => What is the output?


/* const settings = {
name: "Bhavya",
level: 19,
health: 90,
}

const data = JSON.stringify(settings, ["level", "health"])
console.log(data); */


/* ------------------------------------------------------------------------------------------------------------------------------------ */

// Question - 8 => What is the output?

/* const shape = {
radius: 10,
diameter() {
return this.radius * 2;
},
perimeter: () => 2 * Math.PI * this.radius,
};

console.log(shape.diameter());
console.log(shape.perimeter()); */


/* ------------------------------------------------------------------------------------------------------------------------------------ */

// Question - 9 => What is the destructuring in JavaScript?

/* let user = {
name: "Bhavya",
age: 24,
fullName: {
first: "Alex",
last: "jones",
},
}


const name = user

const {fullName: {first} } = user


console.log(first); */



/* ------------------------------------------------------------------------------------------------------------------------------------ */

// Question - 10 => What is the output?


/* let c = { greeting: "Hey!" };
let d;


d = c;
c.greeting = "Hello";
console.log(d.greeting); */


/* ------------------------------------------------------------------------------------------------------------------------------------ */



59 changes: 59 additions & 0 deletions Objects/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Objects in JavaScript

// IIFE


/*const func = (function (a) {
delete a;
return a;
})(5);

console.log(func);

/* ------------------------------------------------------------------------------------------------------------------------------------ */

/*const user = {
name: "Bhavya Khatri",
id: 9315,
"How are you Bhavya": "I am Fine",
};

delete user["How are you Bhavya"];

console.log(user.id); */

/* ------------------------------------------------------------------------------------------------------------------------------------ */

// Dynamic Key value pairs

/*const property = "first name"
const name = "Bhavya Khatri"
const empId = 9315
const empEmailId = "bhavya.khatri@489mango.com"

const users = {
[property]:name, empEmailId, empId
}


console.log(users);*/


/* ------------------------------------------------------------------------------------------------------------------------------------ */


// Looping through objects


/*const User = {
name: "Bhavya Khatri",
id: 9315,
"Good": true
};


for (key in user) {
console.log(User[key]);
}
*/

8 changes: 8 additions & 0 deletions Objects/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
body {
background-color: lightcyan;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}

h1 {
text-align: center;
}