DEV Community

Cover image for The most repeated questions I met with on job interviews (part 1)
Jakub Smetanka
Jakub Smetanka

Posted on • Updated on

The most repeated questions I met with on job interviews (part 1)

A wiseman once said : "If you can not explain it, you do not understand it". A few years ago, when I had searched for a job as a student I went through a lot of interviews. For web positions related to Javascript, there were some questions which repeat regularly. And it makes sense, to asked them also today.

const vs let vs var

const keyword create block scope variable and prevents its value to be reassigned by a new value. However, important thing is that it does not restrict to change the internal state of the object.
image

let is block-scope variable while var is function-scope variable.
image

'===' vs '==' comparison

=== is strict comparison, it checks value and type of value as well, so 1 === "1" returns false, the opposite of that is == comaparison which checks only value so 1 == "1" returns true.

Can we compare two objects with '===' ?

NO. Object is reference type. Two distinct object never be equal even they have same property. That's why you will get false when you are using '===' comparison. In Javascript also exist built-in function Object.is(value1, value2) EDIT: which returns true if objects are equals, otherwise it returns false.

Visit website smetankajakub.com

Follow me on Twitter

Resources

Eloquent Javascript
https://unsplash.com/photos/TFFn3BYLc5s?utm_source=unsplash&utm_medium=referral&utm_content=creditShareLink

Top comments (11)

Collapse
 
sfiquet profile image
Sylvie Fiquet

I was surprised by your assertion that you can use Object.is to compare two objects instead of === so I looked it up on MDN. Like ===, Object.is compares references. It will return false for two distinct objects with the same properties.

The only difference between Object.is() and === is in their treatment of signed zeroes and NaNs.

Collapse
 
smetankajakub profile image
Jakub Smetanka

You are right, thanks, I have edited text

Collapse
 
piyushmbm45 profile image
Piyush Jain

Nice Article Jakub...

Collapse
 
captainyossarian profile image
yossarian

Bte, sometimes I use === to compare obj ref

Collapse
 
arohi profile image
Arohi7892

Very Insightful Blog!

Collapse
 
timbrown profile image
Timothy Brown

Short and useful! Great article!

Collapse
 
ranemihir profile image
Mihir Rane

Short and to the point. Really helpful article, thanks!

Collapse
 
the_one profile image
Roland Doda

I don't think that Object.is returns true if objects are equal:

var foo = { a: 1 };
var bar = { a: 1 };
Object.is(foo, bar); // false

Even empty arrays are not equal:
Object.is([], []); // false

Collapse
 
smetankajakub profile image
Jakub Smetanka

Thanks, my bad. I have edited it.

Collapse
 
sousacaio profile image
Caio frias

Nice iniciative bro, most of my interviews i encounter with these questions.

Collapse
 
smetankajakub profile image
Jakub Smetanka

Glad to hear that