Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 068740f

Browse files
committed
Equality comparisons and sameness
1 parent ee2c0aa commit 068740f

File tree

1 file changed

+40
-11
lines changed

1 file changed

+40
-11
lines changed

‎Interview-Questions/output.js

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,64 @@
11
// 1) What is the output of 10+20+"30" in JavaScript?
22
//Ans: 3030 because 10+20 will be 30. If there is numeric value before and after +, it treats as binary + (arithmetic operator).
3-
3+
44
// 2) What is the output of "10"+20+30 in JavaScript?
55
// Ans: 102030 because after a string all the + will be treated as string concatenation operator (not binary +).
66

77
// 3) Output?
88
// Syncronous
99
[1, 2, 3, 4].forEach((i) => {
10-
console.log(i)
11-
})
10+
console.log(i);
11+
});
1212

1313
// Asynchronous
1414
function asyncForEach(array, cb) {
1515
array.forEach(() => {
1616
setTimeout(cb, 0);
17-
})
17+
});
1818
}
1919

2020
asyncForEach([1, 2, 3, 4], (i) => {
2121
console.log(i);
22-
})
23-
22+
});
2423

2524
// 4) Output? And explain (hint: Octal)
26-
console.log(016)
25+
console.log(016);
2726

28-
console.log(017)
27+
console.log(017);
2928

30-
console.log(026)
29+
console.log(026);
3130

32-
console.log(027)
31+
console.log(027);
3332

3433
// 5) Output?
35-
console.log([...'Hello']);
34+
console.log([..."Hello"]);
35+
36+
// OUTPUT
37+
function sum(a, b) {
38+
a = 10;
39+
return [a + b, arguments[0] + arguments[1]];
40+
}
41+
42+
// in "use strict" => [12, 3]
43+
// in normal mood => [12, 12]
44+
console.log(sum(1, 2));
45+
46+
// Event Propagation
47+
// event.currentTaget.tagName
48+
// this.tagName
49+
50+
// sameValuZero algorithm
51+
const sameValueZero = (a, b) => {
52+
if (a === b || (Number.isNaN(a) && Number.isNaN(b))) {
53+
return true;
54+
}
55+
56+
return false;
57+
};
58+
59+
// Output
60+
// ==, ===, object.is, sameValuZero algorithm
61+
const array = [NaN];
62+
63+
const result = array.includes(NaN);
64+
console.log(result); // True: why? => array.includes follows sameValueZero algorithm

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /