LoginSignup
1
1

More than 1 year has passed since last update.

シンボルとは
*プロパティの重複を避けるために『必ず一意の値』を返す関数。
*文字列でもない、数値でもない、シンボル型という方
*一位なので、比較をすると

シンボル型作成方法

const left = Symbol("hello");
// シンボル型のhelloが返される

同じhelloを左右で比較すると、、

const left = Symbol("hello");
const right = Symbol("hello");
console.log(left == right);
console.log(typeof left)

// ビルドインオブジェクトを拡張するのは好ましくないので、今は確認のため

String.prototype[left] = function(){
	return 'hello'+ this;
} 
const tom = 'Tom';
console.log(tom[left]())
1
1
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
1