Professional Documents
Culture Documents
JS Tricky Questions Part-2
JS Tricky Questions Part-2
JAVASCRIPT
TRICKY
INTERVIEW
QUESTIONS
PART - 2
Swipe >>
1. String Mutability :
azcde? zbcde?
swipe to find out...
@nikhilvallore
Swipe >>
Output: abcde
why?
String is immutable, which means that once a
string is created and assigned a value, it cannot
be changed. However, you can create a new
string with a different value and assign it to the
same variable.
ex:
let text = 'abcde'
text = 'abcdz'
console.log(text)
//output: abcdz
@nikhilvallore
Swipe >>
function foo() {
let a = b = 0;
a++;
return a;
}
foo();
console.log(b);
console.log(a);
@nikhilvallore
Swipe >>
Output:
0
ReferenceError: a is not defined
@nikhilvallore
Swipe >>
3. This :
const obj = {
value: "val1",
prop: {
value: "val2",
print: function(){console.log(this.value)},
},
print: function(){ console.log(this.value) },
print2: () => console.log(this.value)
}
obj.print()
obj.prop.print()
obj.print2()
@nikhilvallore
Swipe >>
@nikhilvallore
Found it interesting?
Follow ME on Linked
for more such content
Nikhil Vallore