Are You Afraid To Solve These 3 JavaScript Questions?

I was too.

Sujit Patil
JavaScript in Plain English
2 min readApr 26, 2022

Recently, I switched my job and attended more than 30 interviews. It was a relatively enjoyable experience and I faced all of the questions with ease. However, there were some that were very tricky to answer like these.

1. Accidental Global Variable

function crazyFunction() {  var a = (b = 10);}crazyFunction();console.log("b", typeof b === "undefined");console.log("a", typeof a === "undefined");

2. Eye Test

const numbers = [1, 2, 3];for (var index = 0; index < numbers.length; index++);{  const number = numbers[index];  console.log(number);}

3. Tricky Closure

let i;for (i = 0; i < 3; i++) {  const log = () => {    console.log(i);  };  setTimeout(log, 100);}

Are you ready to check the answers? Revealing them here.

1. b false
a true
2. undefined3. 3
3
3

I hope you were able to find the answers to these questions.

You can checkout more questions here

Do you want a summary of my reading? Follow me on Twitter, where I post highlights from books and articles!

Cheers!

More content at PlainEnglish.io. Sign up for our free weekly newsletter. Follow us on Twitter and LinkedIn. Join our community Discord.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Published in JavaScript in Plain English

New JavaScript and Web Development content every day. Follow to join our 3.5M+ monthly readers.

Written by Sujit Patil

An Angular developer | Web development enthusiast | sujitpatil.com

Responses (6)

Write a response