npm init > 시작하기
npm i parcel-bundler > parcel bundler설치
npm run dev > 개발 서버를 여는방법
데이터 타입 확인
- typeof, getType
import getType from './getType'
export default
산술, 할당 연산자
-
산술 연산자
+, -, *, /, % 나머지 연산자
-
할당 연산자
let a =2
// a = a + 1
a += 1 =동일 할당 연산자
비교, 논리 연산자
-
비교 연산자
const a = 1
const b = 1
console.log(a === b) : === 일치 연산자
console.log(a !== b) : !== 불일치 연산자
console.log(a < b) : <,>,<=,>=
-
논리 연산자
const a = 1 ===1
const b = 'AB' === 'AB'
const c = true
console.log('&&: ', a && b && c)
&& 그리고 and연산자 = a 그리고 b 그리고 c
console.log('||: ', a || b || c)
|| 또는 or연산자 = a 또는 b 또는 c
console.log('!: ', !a)
! 부정 not연산자
삼항 연산자
- 삼항 연산자
console.log(a ? '참' : '거짓')
항이 3개 ? :
?를 기준으로 앞의값이 true면 :앞의값,
false면 :뒤의값이 출력
조건문 If Else
- If else
const a = random()
if (a === 0) {
console.log('a is 0')
} else if (a === 2) {
console.log('a is 2')
} else {
console.log('rest...')
}
(중간에 구문이 많을경우 else if 여러개 추가 가능)
조건문 Switch
- Switch
const a = random()
switch (a) {
case 0:
console.log('a is 0')
break
case 2:
console.log('a is 2')
break
case 4:
console.log('a is 4')
break
default: (if조건문의 else와 같은구조)
console.log('rest...')
}
반복문
- for(시작조건; 종료조건; 변화조건) { }
for (let i = 0; i < 3; i += 1) {
}
변수 유효범위
- var 함수레벨, / let, const 블록레벨
function scope() {
if (true) {
const a = 123
console.log(a)
}
}
scope()
형 변환
- (자료)형 변환 Type
== 동등 연산자
// Truthy (참 같은 값)
true, { }, [ ], 1, 2, 'false', -12, '3.14' ..
// Falsy (거짓 같은 값)
false, ' ', null, undefined, 0, -0, NaN