JavaScript Interview Questions You Need To Know — Part II

Here are another 5 questions ranging in difficulty.

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

Check out the first part here

Image from Tutorialrepublic

Easy

Q: What is a callback function is and provide a simple example

function writeBlog(topic, callback) {
alert(`Starting my ${topic} blog.`);
// then execute the callback function that was passed
callback();
}

writeBlog('JS', function() {
alert('Finished my blog!');
}
);

If you run this code you will get two alerts. The first will day “Starting my JS blog.” The second will say “Finished my blog!”

Easy/Medium

Q: What is a primitive? What are the primitive values in JavaScript?

  1. Boolean — true or false
  2. Null — no value
  3. Undefined — a variable that is declared but has not been given a value
  4. Number — integers, floats, etc.
  5. String — anything inside of “ ”
  6. Symbol — a unique value that is not equal to any other value (introduced in ES6)
Symbol('x') === Symbol('x') // false

Medium

Q: How can you check if a number is an integer?

function isAnInt(num) {
return num % 1 === 0;
}

console.log(isInt(10)); // true
console.log(isInt(1.1)); // false
console.log(isInt(0.5)); // false

Hard

Q: How does the keyword “this” work? What is an example?

function state() {  console.log(this.name);}
var name = "NY";
var obj1 = { name: "IN", state: state };var obj2 = { name: "CA", state: state };
state(); // "NY"
obj1.state(); // "IN"obj2.state(); // "CA"

The job of state() function is console logging the this.name. This means that it is trying to print the value of the name property of the current execution context (this object).

**this keyword goes much more in-depth, there is default and implicit binding and explicit and fixed binding. Read more about this to get a better understanding.**

Q: What does this code snippet return? True or False?

Number.MIN_VALUE > 0;

The answer is true! You would think MIN_Value is 0 but actually Number.MIN_VALUE is 5e-234. This is the smallest positive number that can be represented as a float. Basically, it is the closest you can get to 0. So what is the smallest value? Number.NEGATIVE_INFINITY.


If you guys have run into some interesting JS questions please feel free to share them in the comments. Maybe I will be able to write a post with user shared questions!

HAPPY NEW YEAR! 2020 😎🥳!

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

10.2K

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