LoginSignup
0
0

More than 1 year has passed since last update.

【javascript】【jquery】パイプライン演算子

Last updated at Posted at 2022-06-29

数値でなければ、任意の数値を表示

コード

process.stdin.resume();
process.stdin.setEncoding('utf8');

let a = 123;
console.log(a|0)
//結果:123

let b = '123';
console.log(b|0)
//結果:123

let c = '0a123';
console.log(c|0)
//結果:0

let d = 'a123';
console.log(d|0)
//結果:0

nullか0なら文字列を表示する

let e = 123;
console.log(e||'データなし')
//結果:123

let f = '';
console.log(f||'データなし')
//結果:データなし

let g = 0;
console.log(g||'データなし')
//結果:データなし
0
0
2

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