Compare Scopes of the var and let Keywords A simple question

Compare Scopes of the var and let Keywords A simple question
0

Tell us what’s happening:

Why can I use a comma (,) instead of a plus (+)?
In ES6 can I concatenate things with “,” and “+”?

Sorry for the inconvenience.

Your code so far


function checkScope() {
"use strict";
  let i = "function scope";
  if (true) {
    let i = "block scope";
    console.log("Block scope i is: "**, i**);
  }
  console.log("Function scope i is: ", i);
  return i;
}
console.log(checkScope()); 

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/compare-scopes-of-the-var-and-let-keywords

console.log() accepts a variable number of arguments and concatenate their string rapresentation together, so you can put different arguments in there and they are all logged to the console, but you are not concatenating the string with the comma - to concat the strings you need +

1 Like

oooohhh okey, in that case i is an argument and because of that it can be represented in the console.log with a comma.

I think I get it, thank you.

no, I mean that console log can takes many arguments:
console.log(obj1, obj2, obj3, ...)

it will be the function itself that concatenate them before printing to the console

1 Like