The problem is if I console log this string: "Lorem "
the console.log
will output: Lorem
and I can't tell if at the end of the string there is white space or not.
How can I force console to show output in quotation marks?
The problem is if I console log this string: "Lorem "
the console.log
will output: Lorem
and I can't tell if at the end of the string there is white space or not.
How can I force console to show output in quotation marks?
Share Improve this question edited Aug 20, 2019 at 17:39 Kamil Kiełczewski 92.4k34 gold badges394 silver badges370 bronze badges asked Aug 20, 2019 at 17:34 TwistedOwlTwistedOwl 1,3242 gold badges18 silver badges33 bronze badges 6 | Show 1 more comment4 Answers
Reset to default 11Try
let s = "Lorem";
console.log( JSON.stringify(s) );
let lorem = "Lorem ";
console.log('"'+lorem+'"');
// Prints: "Lorem "
More generally, the pattern console.log('"'+expression+'"')
will print out the expression with quotes on either side so you can see where the actual beginning and end of the expression is.
If you want this to happen every time, consider creating a function like so:
function myConsole(...expr){
console.log('"'+expr.join(' ')+'"');
}
And using that instead of console.log
Simply escape the slashes:
console.log("\"Lorem \"")
or wrap the double quotes in single quotes (or vice-verse)
console.log('"Lorem "');
To show single quote ( " ) with a string use this syntax
console.log("\"\Your string");
gives output as "Your string
console.log('"Lorem "');
– silencedogood Commented Aug 20, 2019 at 17:35console.log
to always do that. But it's probably too much of a hack to do for the whole application. – VLAZ Commented Aug 20, 2019 at 17:36