Why does this work:


#1

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
#2

Because you concatenate the two together, using +

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


#3

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.


#4

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)


#5

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

Thanks!


#6

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


#7

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


#8

Not exactly. concat() is for concatenating arrays.


#9

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