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?
Try
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
... and .join(' ') it will works too :)console.log is technically variadic, so someone expecting myConsole to work like console.log might reasonably attempt myConsole(anExpression, anotherExpression, aThirdExpression), which wouldn't work without the .... The .join(' ') is unnecessary except that it separates the arguments with a space.
console.log('"Lorem "');console.logto always do that. But it's probably too much of a hack to do for the whole application.