When tracing out variables in the console, How to create a new line?
So I'm trying to do something simple, I want to break up my traces in the console into several lines, using 1 console.log statement:
console.log('roleName = '+roleName+' role_ID = '+role_ID+' modal_ID = '+modal_ID+\n+'related = '+related);
How would you write the above to trace out the following?
roleName = test
role_ID = test
modal_UD = test
related = test
instead of roleName = test role_ID = test modal_UD = test related = test
I've checked out several other questions which appear similar, but none have helped or are talking about a different thing.
Thanks for taking a look!
Solution 1:
You should include it inside quotes '\n'
, See below,
console.log('roleName = '+roleName+ '\n' +
'role_ID = '+role_ID+ '\n' +
'modal_ID = '+modal_ID+ '\n' +
'related = '+related);
Solution 2:
In ES6/ES2015 you can use string literal syntax called template literals. Template strings use backtick character instead of single quote ' or double quote marks ". They also preserve new line and tab
const roleName = 'test1';
const role_ID = 'test2';
const modal_ID = 'test3';
const related = 'test4';
console.log(`
roleName = ${roleName}
role_ID = ${role_ID}
modal_ID = ${modal_ID}
related = ${related}
`);
Solution 3:
Easy, \n
needs to be in the string.