Skip to content

Commit 9daa217

Browse files
committed
day 9 js interview
1 parent 9e3cebb commit 9daa217

1 file changed

Lines changed: 87 additions & 0 deletions

File tree

JavaScript Interview/Day 9/demo.js

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
3+
1. var x = {
4+
a: '1',
5+
b: '2',
6+
a: '3',
7+
'b': 4
8+
}
9+
console.log(x)// a=3 b=4 { a: '3', b: 4 }
10+
11+
12+
2.
13+
console.log(!"hii")// false
14+
15+
16+
3. for(let i=0;i<6;i++){ . First loop with let (Block-scoped):
17+
setTimeout(function(){
18+
console.log(i)
19+
},(10))
20+
}
21+
for(var i=0;i<6;i++){ Second loop with var (Function-scoped):
22+
setTimeout(function(){
23+
console.log(i)
24+
},(10))
25+
}
26+
27+
Ans: 1
28+
2
29+
3
30+
4
31+
5
32+
6
33+
6
34+
6
35+
6
36+
6
37+
6
38+
39+
40+
4. let obj={
41+
name:'rajyalakshmi'
42+
}
43+
let z=obj
44+
z.name='Adil'
45+
console.log(obj.name)// adil
46+
47+
48+
49+
5. let a = 5;
50+
let b = 10;
51+
52+
// Swap values using arithmetic
53+
a = a + b; // a becomes 15 5+10
54+
b = a - b; // b becomes 5 15-10
55+
a = a - b; // a becomes 10 15-5
56+
57+
console.log(a); // 10
58+
console.log(b); // 5
59+
60+
61+
6.
62+
let str = "my name is ram sing";
63+
64+
// Capitalize the first letter of each word
65+
let result = str.replace(/\b\w/g, char => char.toUpperCase());
66+
67+
console.log(result); // Output: "My Name Is Ram Sing"
68+
69+
70+
71+
7.
72+
let str = "Ram Sing";
73+
74+
// Split the string into words, swap them, and join them back
75+
let result = str.split(' ').reverse().join(' ');
76+
77+
console.log(result); // Output: "Sing Ram"
78+
79+
80+
81+
*/
82+
83+
84+
85+
86+
87+

0 commit comments

Comments
 (0)