Member-only story

How to pass Javascript software engineer interview? Most popular questions Questions on Javascript from the FAANG and Unicorns (JUNE 2022 EDITION)

Daniel Mesizah
2 min readJun 6, 2022

--

  1. What are the outputs of the 1st and 2nd for loops?

Ans:

1st for loop:

The number is 10

2nd for loop:

The number is 0

The number is 1

The number is 2

The number is 3

The number is 4

The number is 5

The number is 6

The number is 7

The number is 8

The number is 9

Why?

The value that is declared using var is accessible throughout the entirety of the program because var has function scope, or in more colloquial terms, global scope. Alternatively, let is locally scoped, which means that it is only accessible within the context of a single block. As was pointed out by, you need to make the val available locally within the loop by using the let statement. Only then will you be able to notice the change.

--

--

Daniel Mesizah
Daniel Mesizah

Written by Daniel Mesizah

Coder who likes to share what he knows with the rest of the world

No responses yet