This is more of the differences of console.log using a comma to separate them will log them as separate objects, + will concatenate/add them (and probably end up being a string). but you can use sprintf-like formatters in console.log: console.log("My name is %s", "Example");
The difference appears when you want to include an object, or another non-string. Of course, it all depends on the browser too, since there are no standards for console
Yes, in the example you gave the two forms will produce the same output. However, this is behavior specific to console.log and you cannot in general join two strings using a comma.
Sign up to request clarification or add additional context in comments.
Comments
0
+concatenates a string (i.e. combines them). In your first example, console.log takes one argument: "My name is " + myName as a single combined string. In your second example, console.log takes two arguments: "My name is" and myName, as separate strings.
console.logusing a comma to separate them will log them as separate objects,+will concatenate/add them (and probably end up being a string). but you can usesprintf-like formatters inconsole.log:console.log("My name is %s", "Example");