기본값: [숫자 : 12, 문자열 : "Hello"]
산술연산자: [+, -, *, /, % ]
비교연산자: [<, >, <=, >=, ==, !=, ===, !==]
관계연산자: [&&, ||]
==는 값을 비교, ===는 주소를 비교하는 연산자이다.
var x = 3;
var y = 3;
document.write(x==y); //true
document.write(x===y); //true
var x = 3;
var y = new Number(3);
document.write(x==y); //true
document.write(x===y); //false
직접 boxing을 해줘야 한다!
식: condition ? exprIfTrue : exprIfFalse
condition: 조건
expIfTrue: 참 일때 실행할 식
expIfFalse: 거짓 일때 실행할 식
주로 if문을 단축할 때 사용.
function getFee(isMember) {
return (isMember ? '$2.00' : '$10.00');
}
console.log(getFee(true));
//output: "$2.00"
console.log(getFee(false));
//output: "$10.00"
console.log(getFee(null));
//output: "$10.00"
출처 : 삼항연산자
뺼셈에서는 문자열이 숫자가 되고, 덧셈에서는 숫자가 문자열이 된다.
document.write(3.5-"2"); //1.5
document.write(3.5+"4"); //"3.54"
비교연산자는 숫자로 변환해 비교한다.
document.write("100" > "10"); //true
document.write(100 > "1000"); //false