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
- [다중정렬]data.sort((a, b) => a.price - b.price || a.name.localeCompare(b.name)); 2024.03.22 js/js syntax
- {...{id:1,value:일},id:2} ->젤 뒤에 오는 2가 앞의 1을 덮어버림, 앞에 위치한 값은 없어짐 2024.02.07 js/js syntax
- 1->01: (1+'').padStart(2,'0'), (1).toLocaleString('en-US',{minimumIntegerDigits:2}) 2024.01.31 js/js syntax
- javascript true/false 2022.08.31 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' 카테고리의 다른 글
[다중정렬]data.sort((a, b) => a.price - b.price || a.name.localeCompare(b.name));
data.sort((a, b) => a.price - b.price || a.name.localeCompare(b.name)); // 가격이 낮은 순으로 정렬하고, 가격이 같으면 이름순으로 정렬
'js > js syntax' 카테고리의 다른 글
{...{id:1,value:일},id:2} ->젤 뒤에 오는 2가 앞의 1을 덮어버림, 앞에 위치한 값은 없어짐
{...{id:1,value:일},id:2} ->뒤에 오는 2를 사용함, 앞에 위치한 값은 없어짐
뒤가 중요
'js > js syntax' 카테고리의 다른 글
[numberCheck] /^\d+$/.test(확인대상-문자열, 문자열아니면 문자열로 자동변환) Number.isInteger(확인대상-숫자, 그중에서도 정수만 true 1.0도 true) (0) | 2024.04.01 |
---|---|
[다중정렬]data.sort((a, b) => a.price - b.price || a.name.localeCompare(b.name)); (0) | 2024.03.22 |
1->01: (1+'').padStart(2,'0'), (1).toLocaleString('en-US',{minimumIntegerDigits:2}) (0) | 2024.01.31 |
javascript true/false (0) | 2022.08.31 |
js reduce function (0) | 2022.08.22 |
1->01: (1+'').padStart(2,'0'), (1).toLocaleString('en-US',{minimumIntegerDigits:2})
(1+'').padStart(2,'0')
(1).toLocaleString('en-US',{minimumIntegerDigits:2}) 동작함
1.toLocaleString('en-US',{minimumIntegerDigits:2}) 에러남
'js > js syntax' 카테고리의 다른 글
[다중정렬]data.sort((a, b) => a.price - b.price || a.name.localeCompare(b.name)); (0) | 2024.03.22 |
---|---|
{...{id:1,value:일},id:2} ->젤 뒤에 오는 2가 앞의 1을 덮어버림, 앞에 위치한 값은 없어짐 (0) | 2024.02.07 |
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' 카테고리의 다른 글
{...{id:1,value:일},id:2} ->젤 뒤에 오는 2가 앞의 1을 덮어버림, 앞에 위치한 값은 없어짐 (0) | 2024.02.07 |
---|---|
1->01: (1+'').padStart(2,'0'), (1).toLocaleString('en-US',{minimumIntegerDigits:2}) (0) | 2024.01.31 |
js reduce function (0) | 2022.08.22 |
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 |