JavaScript Function Question

function sayThanks(name) {
console.log("Thank you for your purchase " + name + “! We appreciate your business.”);


Why do I have to put quotations around the name Cole for the code to run?
i.e. Why won’t sayThanks(Cole); run?

1 Like

It has to do with character data, which is delimited by quotes, as in string type. Remove the quotes and the interpreter will see it as an identifier and will look to the namespace for that variable reference.

var cole = "Cole"

See how that works?

1 Like

Yes, that’s a really helpful description.


1 Like