반응형
반응형
반응형

const a = arg||'default' 주로 이렇게 초기화용도로 쓰는데 0, ''도 정상값일 경우는 ??를 쓰면 됨

 

Nullish coalescing operator

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing

 

Logical or operator

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR

 

 

반응형
반응형

[...Array(N).keys()]

Array.from(Array(N).keys())

반응형
반응형
반응형
반응형
/^\d{1,7}$/.test(refCost.current.value)

postgreSQL numeric(10,3)이면 숫자가 최대 7자, 소수점 3자리까지 가능

7자리 넘으면 에러 발생, 7자리 체크위해서 regex사용가능

제한없이 숫자만 입력받으려면 {1,7} -> +로 변경

/^\d+$/.test(refCost.current.value)

 

반응형
반응형

/^\d+$/.test('123') true

/^\d+$/.test(123) true

/^\d+$/.test(123.0) true -> 123.0을 string으로 변환한후에 체크하는 듯

/^\d+$/.test('123.0') false

/^\d+$/.test('123r') false

 

Number.isInteger(123) true

Number.isInteger(123.0) true

Number.isInteger(123.1) false

Number.isInteger('123') false

반응형
반응형

  let test = '  ';

  console.log('[test]'test);

  if (testconsole.log('[TRUE]'); //' ', 1, -1, 1 / 0=Infinity,[],{}, () => {}

  else console.log('[FALSE]'); //undefined,null,'', false, 0, 0 / 0=NaN

반응형
반응형
reduce(callbackFn, initialValue)
  • initiallValue없으면? If initialValue is not specified, previousValue is initialized to the first value in the array, and currentValue is initialized to the second value in the array.
  • initialValue없고 대상array내 값이 1개뿐이라면?
    • 뭘해도 [A] -> reduce(...) -> A 형태로 결과가 나옴, 즉 1개 있던 value가 array를 빠져나오게됨

 

reduce((previousValue, currentValue, currentIndex, array) => { /* … */ }, initialValue)
  • previousValue: accumulated values until now
반응형
반응형

 

  • array===[] (X)
  • array && array.length===0 (O)
  • array && !array.length (O)

 

반응형
반응형

그냥 이렇게 쓰면 됨, ``내부에 또 ``넣는 건 안되는듯

json.data[0].word
  ? `${json.data[0].word} (${json.data[0].reading})`
  : `${json.data[0].reading}`
반응형

+ Recent posts