While, I’m playing with the Prototype, I want to show the multiple variables like
Person.prototype.lastName = 'Verma';
Person.prototype.companyName = 'Abihi'
console.log(john.lastName);
How can I add the companyName without creating the second console.log like console.log(john.companyName);
Is there any way to write side by side - “Verma, abihi” ?
hi, just separate them by commas console.log(var1, var2, var3);
1 Like
To get the formatting as you’ve shown in your desired output, try
console.log(var1 + ', ' + var2);
2 Likes
Or using template strings:
console.log(`First name: ${var1}, last name: ${var2}`);
1 Like
Yet another way… :-)
console.log('%s, %s', var1, var2)
I just tried that way (curiosity is a terrible affliction you know), and got an output in the format…
// "%s, %s" "var1" "var2"
Is that what you’d have expected, or have I misunderstood something?
Huh… not sure, this works fine in chrome and firefox:
var var1 = 'foo', var2 = 'bar'
console.log('%s, %s', var1, var2)
Which browser are you using? It’s certainly odd that those variable names are getting interpreted as strings…
1 Like
I’m in Chrome, but was using the Codepen console (there was a tab open). Best check it in a proper console then.
1 Like
Maybe it’s an addition of npm, who knows these days?
I have never seen it that way but then again I’m falling far behind the npm boat
That works better. Lesson noted.
It’s a WHATWG specification. ;-)
1 Like
system
Closed
13
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.