js/js syntax
- Optional chaining (?.) 2024.06.18 js/js syntax
- (Nullish coalescing??: null,undefined일때만) vs (||: falsy-null,undefined,0,'',NaN..) 2024.06.18 js/js syntax
- How to create an array containing 0...N-1: [...Array(N).keys()], Array.from(Array(N).keys()) 2024.04.18 js/js syntax
- [js regex] /^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!%*#?&]{8,}$/ 8자리이상 문자,숫자,특수문자 포함 2024.04.01 js/js syntax
- [js regex] /^\d{1,7}$/.test('string') 'string'이 1에서7자리 자연수인지 체크 (최대7자리수까지 입력가능하도록 체크) 2024.04.01 js/js syntax
- [numberCheck] /^\d+$/.test(확인대상-문자열, 문자열아니면 문자열로 자동변환) Number.isInteger(확인대상-숫자, 그중에서도 정수만 true 1.0도 true) 2024.04.01 js/js syntax
- javascript true/false 2022.08.31 js/js syntax
- js reduce function 2022.08.22 js/js syntax
- js empty array check: arr?.length===0 (객체이면 arr.length는 undefined) 2022.07.11 js/js syntax
- js template literal에서 삼항연산자(a?b:c, ternary operator) 사용 2022.06.02 js/js syntax
Optional chaining (?.)
(Nullish coalescing??: null,undefined일때만) vs (||: falsy-null,undefined,0,'',NaN..)
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
'js > js syntax' 카테고리의 다른 글
How to create an array containing 0...N-1: [...Array(N).keys()], Array.from(Array(N).keys())
[...Array(N).keys()]
Array.from(Array(N).keys())
'js > js syntax' 카테고리의 다른 글
[js regex] /^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!%*#?&]{8,}$/ 8자리이상 문자,숫자,특수문자 포함
'js > js syntax' 카테고리의 다른 글
[js regex] /^\d{1,7}$/.test('string') 'string'이 1에서7자리 자연수인지 체크 (최대7자리수까지 입력가능하도록 체크)
postgreSQL numeric(10,3)이면 숫자가 최대 7자, 소수점 3자리까지 가능
7자리 넘으면 에러 발생, 7자리 체크위해서 regex사용가능
제한없이 숫자만 입력받으려면 {1,7} -> +로 변경
/^\d+$/.test(refCost.current.value)
'js > js syntax' 카테고리의 다른 글
[numberCheck] /^\d+$/.test(확인대상-문자열, 문자열아니면 문자열로 자동변환) Number.isInteger(확인대상-숫자, 그중에서도 정수만 true 1.0도 true)
/^\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
'js > js syntax' 카테고리의 다른 글
[js regex] /^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!%*#?&]{8,}$/ 8자리이상 문자,숫자,특수문자 포함 (0) | 2024.04.01 |
---|---|
[js regex] /^\d{1,7}$/.test('string') 'string'이 1에서7자리 자연수인지 체크 (최대7자리수까지 입력가능하도록 체크) (0) | 2024.04.01 |
javascript true/false (0) | 2022.08.31 |
js reduce function (0) | 2022.08.22 |
js empty array check: arr?.length===0 (객체이면 arr.length는 undefined) (0) | 2022.07.11 |
javascript true/false
let test = ' ';
console.log('[test]', test);
if (test) console.log('[TRUE]'); //' ', 1, -1, 1 / 0=Infinity,[],{}, () => {}
else console.log('[FALSE]'); //undefined,null,'', false, 0, 0 / 0=NaN
'js > js syntax' 카테고리의 다른 글
js reduce function
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
'js > js syntax' 카테고리의 다른 글
[numberCheck] /^\d+$/.test(확인대상-문자열, 문자열아니면 문자열로 자동변환) Number.isInteger(확인대상-숫자, 그중에서도 정수만 true 1.0도 true) (0) | 2024.04.01 |
---|---|
javascript true/false (0) | 2022.08.31 |
js empty array check: arr?.length===0 (객체이면 arr.length는 undefined) (0) | 2022.07.11 |
js template literal에서 삼항연산자(a?b:c, ternary operator) 사용 (0) | 2022.06.02 |
Javascript Array Function - Map (0) | 2019.10.24 |
js empty array check: arr?.length===0 (객체이면 arr.length는 undefined)
- array===[] (X)
- array && array.length===0 (O)
- array && !array.length (O)
'js > js syntax' 카테고리의 다른 글
[numberCheck] /^\d+$/.test(확인대상-문자열, 문자열아니면 문자열로 자동변환) Number.isInteger(확인대상-숫자, 그중에서도 정수만 true 1.0도 true) (0) | 2024.04.01 |
---|---|
javascript true/false (0) | 2022.08.31 |
js reduce function (0) | 2022.08.22 |
js template literal에서 삼항연산자(a?b:c, ternary operator) 사용 (0) | 2022.06.02 |
Javascript Array Function - Map (0) | 2019.10.24 |
js template literal에서 삼항연산자(a?b:c, ternary operator) 사용
그냥 이렇게 쓰면 됨, ``내부에 또 ``넣는 건 안되는듯
json.data[0].word
? `${json.data[0].word} (${json.data[0].reading})`
: `${json.data[0].reading}`
'js > js syntax' 카테고리의 다른 글
[numberCheck] /^\d+$/.test(확인대상-문자열, 문자열아니면 문자열로 자동변환) Number.isInteger(확인대상-숫자, 그중에서도 정수만 true 1.0도 true) (0) | 2024.04.01 |
---|---|
javascript true/false (0) | 2022.08.31 |
js reduce function (0) | 2022.08.22 |
js empty array check: arr?.length===0 (객체이면 arr.length는 undefined) (0) | 2022.07.11 |
Javascript Array Function - Map (0) | 2019.10.24 |