체 리터럴 대신 스위치

코드 예제

0
0

를 사용하지 않는 경우-다른 사와 스위치에서 자바스크립트,사용하는 개체 리터럴

const getValue = (value) => ({
  [value == 1]: 'Value is 1',
  [value > 1]: 'Value is greater than 1',
  [value < 1]: 'Value is less than 1',
})[true]

console.log(getValue(2));
console.log(getValue(-1)); 
console.log(getValue(-1+2)); // expect 'Value is 1'
0
0

자바스크립트 객체를 대신 스위치

const dogSwitch = (breed) => ({
  "border": "Border Collies are good boys and girls.",
  "pitbull": "Pit Bulls are good boys and girls.",
  "german": "German Shepherds are good boys and girls."
})[breed]
dogSwitch("border") // "Border Collies are good boys and girls."

비슷한 페이지

예제가있는 유사한 페이지

다른 언어로

이 페이지는 다른 언어로되어 있습니다

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................