When tracing out variables in the console, How to create a new line?

后端 未结 7 1334
孤街浪徒
孤街浪徒 2021-01-30 03:39

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 = \'         


        
7条回答
  •  死守一世寂寞
    2021-01-30 04:12

    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}
    `);

提交回复
热议问题