Why does this work:


Why does this work:

 console.log("Hi, I work as a " + this.job);

but this gives an error "
Oops, try again. It looks like your sayJob() method does not properly log 'Hi, I work as a [job]' to the console"

console.log("Hi, I work as a ", this.job);

the difference is the + vs the ,

4/30 can I see your references

Because you concatenate the two together, using +

It links "Hi, I work as a " and this.job together. The comma does not.


it works in Chrome dev tools, but HOW it's working is the mystery. I understand that + is to concatenate, but I'm guessing the , is kind of just passing along the property as a separate thing. It displays the same, but it's not REALLY doing the same thing.


And I just discovered something thanks to you. I didn't know. Just tried it, and it does work...
I'm looking it up as I don't recall having ever seen this before.

(My best bet being that it's due to Javascript being way too lenient)


Loosey Goosey as usual ,but I'm assuming there is a 'technical' explanation.
If you find out, please post. I'm looking as well.



Okay so it appears to be working like the concat() method, but without it?


The guy who wrote the course replied to me on Twitter.


Not exactly. concat() is for concatenating arrays.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.