JavaScript Interview Questions You Need To Know

Adi S
Adi S
Dec 25, 2019 · 3 min read

This week I am writing about JS questions you may encounter during an interview. Will start with 5 questions ranging in difficulty. If you guys want more questions, leave comments below and I’ll continue this series next week!

Why JavaScript? Well for full stack developers JavaScript may be considered the Holy Grail. JS has been ranked the most commonly used programming language for SEVEN YEARS IN A ROW according to Stack Overflow’s annual Developer Survey! Python is climbing the ranks, just beating Java, but JS is still king/queen 👑.

JavaScript for the win…again

Since JS is integral to full stack developers, let’s stick with it.

Easy

Q: Explain equality in JavaScript

A: In Java we have two comparisons, strict and type-converting.

Strict comparison or equality is the triple equals ===

Both the type and value have to be the same, for example:

10 === 10 // true'hello world' === 'hello world' // true because both are strings and equal values23 === '23' // false because you are comparing a Number to a String

Strict comparison does not allow coercion.

Since some of you may not be familiar with coercion, I will show a quick example below:

In JS, coercion is the conversion between two built in data types.

Explicit coercion:

let a = '23';
let b = Number(a);
a; // '23'
b; // 23 (this is the Number 23 not the String)

Implicit coercion:

let a = '23';
let b = a * 2; // '23' is implicitly coerced to 23
a; // '23'
b; // 46 (this is the Number 46 not a String)

Abstract comparison or Double Equals ==

Abstract comparison is compares value equality and coercion is allowed. So the two values are compared after attempting to convert them to the same data type.

23 == '23' // true

Q: What is the difference between Null and Undefined

A: When something is not initialized it is undefined. When something is not currently available to use it is null.

Medium

Q: What are IIFEs (Immediately Invoked Function Expressions)?

A: An Immediately Invoked Function Express is executed immediately after it is created.

(function iifeExample() {

console.log('Hello, World!');

})(); // Hello, World!

Q: What is the difference between anonymous and named functions?

function foo(){
alert("Hi, I'm foo!");
}
var bar = function(){
alert("I am an anonymous function that is assigned to the variable "bar");
}
foo(); // "Hi, I'm foo!"
bar(); //"I am an anonymous function that is assigned to the variable "bar"

An anonymous function is simply a function with no name and are all created on application runtime.

As you can imagine Named Functions are quite useful when debugging and looking for what functions caused errors.

Hard

Q: What will the following code output?

0.1 + 0.2 === 0.3

This surprisingly returns false! Why? Because floating point is not represented properly internally. So for example 0.1 + 0.2 will equal 0.30000000000000004. Weird right? Again the reason for this is the computer cannot represent the float accurately. One workaround would be to round the number when executing arithmetic with decimals.

Don’t believe me? Try it for yourself 😉

Happy Holidays!

JavaScript in Plain English

Learn the web's most important programming language.

Adi S

Written by

Adi S

JavaScript in Plain English

Learn the web's most important programming language.

More From Medium

More from JavaScript in Plain English

More from JavaScript in Plain English

32 funny Code Comments that people actually wrote

More from JavaScript in Plain English

More from JavaScript in Plain English

How Single Page Applications Broke Web Design

More from JavaScript in Plain English

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade