1
0

More than 1 year has passed since last update.

【P】Primitiveな値

Last updated at Posted at 2022-12-15

Primitiveとは?

オブジェクトじゃなくて、メソッドも持たない。
文字列、数値、BigInt、真偽値、undefined(、シンボル)が該当

判定方法

typeof演算子を使う。nullは"object"を返すのでそこだけ注意。

isPrimitive.js
const isPrimitive = (i) => {
    return i == null || typeof i != "object";
}

もっと簡略化した書き方

そういえばこの記事で中身1行のアロー関数式の短縮をやった覚えがあるな、となったので。

isPrimitive.js
const isPrimitive = i => i == null || typeof i != "object";
1
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
1
0