Need help in variables


#1

code
var myPet = ‘armadillo’;
console.log('I own a pet ’ + myPet + ‘.’);
prints same result as code

var myPet = ‘armadillo’;
console.log(‘I own a pet ’ + myPet);
then what +’.’ is actually do in first code ?


#2

because the + '.' will add a full stop at the end, for example you own a cat:

i own a pet cat.

vs

i own a pet cat

see? No full stop at the end of the sentence


#3

Taken from MDN an example of string interpolation or concatenation, with embedded expressions


#4

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