Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- UI
- CSS
- variable#function
- for~in/for~of
- react
- redux상태유지
- slice/splice/split
- @redux-toolkit
- toString#String
- JS#3일차달리자#초반인데#시간금방~
- 내장고차함수
- 자바스크립트#조건문#문자열
- js
- https://developer-talk.tistory.com/299
- 헷갈린다~
- children vs childrenNodes
- UX
- removeCookie
- ㄷㅌ
- 자바스크립트#JS#slice#splice
- 자바스크립트#JS#var#let#const#undefined#null
- https://www.daleseo.com/js-array-slice-splice/
- cmarket
- User Flow
- dom
- https://dasima.xyz/%EC%9E%90%EB%B0%94%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8-%EC%A0%9C%EA%B3%B1-math-pow-%EA%B3%84%EC%82%B0/
- 자바스크립트
- https://lo-victoria.com/introduction-to-redux-toolkit-for-beginners
- Beesbeesbees
- 노드교과서
Archives
- Today
- Total
Daily Front_Minhhk
[9장] 자바스크립트 딥다이브_타입 변환, 단축 평가 본문
명시적 타입 변환 , 타입 캐스팅 → 개발자가 의도적으로 값의 타입을 변환 하는 것
암묵적 타입 변환, 타입 강제 변환 → 개발자 의도와 상관 없이, js엔진에 의한 변환
fasly 값 :
false, undefined, null, 0, -0, NaN, ‘’
// 문자열 변환
String(1); // “1”
(1).toString() // "1"
1 + '' ; // "1"
// 숫자 변환
Number('1') // 1
parseInt('1') // 1
+'1' // 1
+true // 1
'1'* // 1
// 불리언 변환
Boolean('x') // true
Boolean('1') // true
Boolean(0) // false
Boolean('') // false
Boolean(Nan, null, undefined) // false
Boolean(Infinity) // true
// 빈배열, 빈객체는 true
Boolean({}) // true
Boolean([]) // true
단축평가
// && (AND)
'Cat' && 'Dog' // "Dog"
좌 → 우항 평가 진행
마지막 ‘Dog’ true 값 출력,,
정확한 boolean 을 위해
좌항에 !! 추가
// || (OR)
'Cat'|| 'Dog' // "Cat"
좌 → 우항 평가 진행
‘Cat’ 이 true?
‘Cat’ true 값 출력
옵셔널 체이닝 연산자__ ?.
→ 좌항이 null || undefined 일 땐, undefined 반환
let str = null;
let length = str?.length
console.log(length) // undefined
→ 좌항 피연산자가 falsy 값 이라도, null || undefined 가 아니면 우항의 프로퍼티 참조
let str ='';
let length = str?.length
console.log(length) // 0
null 병합 연산자__ ??
→ 변수에 기본 값을 설정할 때
// 좌항의 피연산자가 null || undefined 이면 우항의 피연산자 반환
// 그렇지 않으면 좌항 피연산자 반환
let a = null ?? 'default'
console.log(a) // 'default'
// 이전에는 || 논리연산자로 비교 했다.
let a = '' || 'default'
console.log(a) // 'default'
👺 하지만, null 병합 연산자는 좌항의 피연산자가 falsy 값이라도,
null 과 undefined 가 아니면 좌항의 피연산자를 반환
//
let a = '' ?? 'default'
console.log(a) // ''
'Study > JS_딥다이브' 카테고리의 다른 글
[13~15장] 자바스크립트 딥다이브_스코프, 전역변수 문제점, let-const 와 블록 레벨 스코프 (0) | 2023.11.23 |
---|---|
[12장] 자바스크립트 딥다이브_함수 (1) | 2023.11.23 |
[10~11장] 자바스크립트 딥다이브_객체, 원시값과 객체 비교 (0) | 2023.11.23 |
[6~8장] 자바스크립트 딥다이브_데이터 타입, 연산자, 제어문 (0) | 2023.11.23 |
[1~5장] 자바스크립트 딥다이브_프로그래밍, 변수, 표현식과 문 (1) | 2023.11.23 |