|| 연산은 왼쪽이 참이면 오른쪽을 읽지 않음
&& 연산은 오른쪽부터 읽음
var name = "crong";
var result = name || "codesquad";
console.log(result);
결과 crong
var name = "crong";
var result = name && "codesquad";
console.log(result);
결과 codesquad
0 == false 는 true
"" == false 는 true
null == false 는 false
0 == "0"는 true
==과 ===는 다르다
===는 타입까지 검사
null == undefined 는 true
toString.call(변수)로 타입 확인
배열은 isArray가 있음
for문에서 arry.length 사용시 매번 루프 돌때마다 길이를 측정하므로 길이는 미리 따로 변수로 빼서 성능 향상
typeof "abc" -> String
typeof "a" -> String
typeof 'a' -> String
"ab:cd".split(":"); //["ab","cd"]
"ab:cd".replace(":", "$"); //"ab$cd"
" abcde ".trim(); //"abcde"
호이스팅
function test() {
console.log(printName());
var printName = function() {
return 'anonymouse';
}
}
test();
이러면 undefined
function test() {
console.log(printName());
function printName() {
return 'anonymouse';
}
}
test();
이러면 제대로 출력
var로 선언하면 함수를 호출하기 전에 선언해야 하지만
함수로 선언하면 호출하기 전에 불러도됨
function a(){
}
console.log(a());
결과: undefiend
'JavaScript' 카테고리의 다른 글
JavaScript 문법 메모3 (0) | 2024.02.28 |
---|---|
Ajax 통신 (0) | 2024.02.22 |
Browser Event (0) | 2024.02.22 |
DOM 정의 및 활용 (0) | 2024.02.22 |
JavaScript 문법 메모2 (0) | 2024.02.22 |