JavaScript Interview Questions that made me think — Do I really know JavaScript? — Part 2
Javascript tricky interview questions
3 min readNov 3, 2022
JavaScript never fails to amaze me, below are the few questions which made think twice before coming to a conclusion.
What will be printed in console?
.
.
.
It will print:2
2.length property on function prints the length of arguments a function is expecting.
And if there is any optional argument, then all argument after that will be considered option, not matter if we declare them optional or not.With that said, it is always a good practice to include optional arguments in the last.
What is the value of this
inside a static function?
.
.
.
The value of this inside a static function is class itself.When we log this inside static method whole class will be logged.// Output
class Test {
constructor(lang) {
this.lang = lang;
}
static showName() {
console.log(this, this.lang);
}
}
What will be printed in console?
.
.
.
true
true
true
false
How to check whether the object value is an object or not?
.
.
.
What will be printed in console?
.
.
.
HelloHowHelloHow are you?
What will be printed in console?
.
.
.
When we do .toString() in an array, it will stringily the elements inside it, if it contains primitive values.And toString() also flatten the array.Output:"4,5,6,3,4,5"
What are the three event phases? Write them in the order they occur.
.
.
.
1. Capturing phase – the event goes down to the element.
2. Target phase – the event reached the target element.
3. Bubbling phase – the event bubbles up from the element.Order Will be 1 then 2 then 3
What will be printed in console?
.
.
.
obj.showLang() will print undefinedx.showLang() will print Vue
What will be printed in console?
.
.
.
112undefined
Here is part 1 of the series:
https://rahuulmiishra.medium.com/javascript-interview-questions-that-made-me-think-do-i-really-know-javascript-2904588ebd5a
here is part 3 of the series:
https://rahuulmiishra.medium.com/javascript-interview-questions-that-made-me-think-do-i-really-know-javascript-part-3-e9febba342b4
here is part 4 of the series:
here is the part 5 of the series:
https://rahuulmiishra.medium.com/javascript-interview-questions-that-made-me-think-do-i-really-know-javascript-part-5-41b5793456d8