Skip to content

Commit db64ed4

Browse files
committed
day 11 js interview
1 parent 18c0f3e commit db64ed4

1 file changed

Lines changed: 171 additions & 0 deletions

File tree

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
/*
2+
3+
Condition Check (if (num)):
4+
5+
In JavaScript, the if statement checks whether num is truthy or falsy.
6+
A falsy value is a value that evaluates to false in a Boolean context. Common falsy values include 0, "" (empty string), null, undefined, and false.
7+
A truthy value is anything that is not falsy. For example, all non-zero numbers are truthy.
8+
Execution of Code Inside if:
9+
10+
If num is truthy, the count variable is incremented by 1.
11+
Iterating Over the Array:
12+
13+
When num = 0: if (0) evaluates to false, so count remains 0.
14+
When num = 1: if (1) evaluates to true, so count becomes 1.
15+
When num = 2: if (2) evaluates to true, so count becomes 2.
16+
When num = 3: if (3) evaluates to true, so count becomes 3.
17+
18+
19+
1. let count = 0;
20+
const nums = [0, 1, 2, 3];
21+
22+
nums.forEach(num => {
23+
if (num) {
24+
count = count + 1;
25+
}
26+
});
27+
28+
console.log(count);//3
29+
30+
31+
32+
2. console.log(typeof typeof(10))//string
33+
console.log(typeof Array) //funtion
34+
35+
class abc {
36+
37+
}
38+
console.log(typeof abc)//function
39+
40+
41+
console.log(typeof 10)//number
42+
console.log(typeof "10")//string
43+
console.log(typeof NaN)//number
44+
console.log(typeof Boolean)//function
45+
console.log(typeof undefined)//undefined
46+
console.log(typeof parseFloat)//function
47+
console.log(typeof Symbol)//function
48+
console.log(typeof BigInt)// function
49+
50+
51+
$full=5;
52+
console.log($full);//5
53+
54+
z=BigInt("9");
55+
console.log(z);//9n
56+
57+
let p=Symbol("hello");
58+
console.log(p);//Symbol(hello)
59+
60+
61+
3. function myFunc() {
62+
"use strict"
63+
xyz = 100;
64+
console.log(xyz);
65+
}
66+
67+
console.log(myFunc());//error
68+
69+
70+
function myFunc() {
71+
72+
xyz = 100;
73+
console.log(xyz);
74+
}
75+
76+
console.log(myFunc())// 100 underdefined
77+
78+
79+
80+
81+
function myFunc() {
82+
83+
var xyz = 100;
84+
console.log(xyz);
85+
}
86+
87+
console.log(myFunc())// 100 underdefined
88+
89+
90+
function myFunc() {
91+
"use strict"
92+
let xyz = 100;
93+
console.log(xyz);
94+
}
95+
96+
console.log(myFunc())// 100 underdefined
97+
98+
99+
100+
4.
101+
102+
var: variable can be redeclared & updated. A global scope variable before 2015 we used var
103+
104+
105+
but in 2015 in javascript has new features called ES6 and we use the following keyword
106+
107+
let:variable can not be re-declared but can be updated. block scope variable.
108+
109+
const: variable can not be re-declared or updated.A block scope variable.
110+
111+
112+
i)var xyz=1 + abc//1+ undefined =NAN
113+
var abc=100
114+
console.log(xyz)//NAN
115+
116+
117+
118+
ii)var xyz=1 + abc
119+
abc=100
120+
console.log(xyz)//ERROR REF
121+
122+
iii)let xyz=1 + abc
123+
let abc=100
124+
console.log(xyz)//ERROR REF
125+
126+
127+
iv)const xyz=1 + abc
128+
const abc=100
129+
console.log(xyz)//ERROR REF
130+
131+
132+
5.
133+
const data = {
134+
name: "Nabil",
135+
}
136+
137+
const abc = [1, 2, 3, 4]
138+
console.log(delete data);//false
139+
console.log(delete abc);//false
140+
141+
Explanation of the delete Operator:
142+
The delete operator in JavaScript is used to remove properties from objects, not variables or constants.
143+
delete can only work on properties of objects that are configurable.
144+
Trying to use delete on a variable, function, or constant will not remove it but will typically result in false.
145+
146+
147+
148+
6.
149+
150+
const a = [];
151+
const b = [];
152+
console.log(a == b); // false
153+
console.log(a === b); // false
154+
155+
156+
157+
158+
1. Arrays are Objects in JavaScript
159+
Both a and b are arrays, and arrays in JavaScript are objects.
160+
When comparing objects (or arrays), the comparison checks whether the two operands refer to the same memory location (i.e., the same instance in memory), not whether their contents are the same.
161+
2. a == b
162+
The == operator performs a loose equality check. It checks if a and b refer to the same object in memory.
163+
Here, a and b are two separate arrays (two separate instances in memory). Even though both are empty, they are distinct objects.
164+
Therefore, a == b evaluates to false.
165+
166+
*/
167+
168+
169+
170+
171+

0 commit comments

Comments
 (0)