0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

EJSでもconsole.logが使える。デバッグに便利。

Posted at

EJSでも、JavaScriptでおなじみのconsole.log()を使うことで実行環境へログを出力することができます。

<% 
    const person = 'taro';
    console.log(person); 
%>
taro

使用しているNode.jsがv10が以上であればconsole.table()なども使うことができます。

<% 
    const people = [
      {name: 'taro', age: 66},
      {name: 'shota', age: 33},
      {name: 'hiroto', age: 10},
    ];
    console.table(people); 
%>
┌─────────┬──────────┬─────┐
│ (index) │   name   │ age │
├─────────┼──────────┼─────┤
│    0    │  'taro'  │ 66  │
│    1    │ 'shota'  │ 33  │
│    2    │ 'hiroto' │ 10  │
└─────────┴──────────┴─────┘

混みいったコードを書く時にデバッグとして使うと便利です。

参考記事

Node.js v10.0.0でconsole.table()追加&console.log()アップデートに感動したので早速試してみる

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?