Home » Javascript » FizzBuzz for Javascript: How console.log knows when to print one variable or another?

FizzBuzz for Javascript: How console.log knows when to print one variable or another?

Posted by: admin October 18, 2018 Leave a comment

Questions:

I’m looking at this code:

for (let n = 1; n <=100; n++) {
  let output = "";
  if (n % 3 == 0) output += "Fizz";
  if (n % 5 == 0) output += "Buzz";
console.log(output || n);
}

How the console decides when to print the numbers or the words?

Answers: