JavaScript 총정리 - 목차로 바로가기
Unary operators (단항 연산자)
- operand(피연산자)가 하나만 있는 연산.
delete
delete object.property;
delete object[propertyKey];
delete property; // legal only within a with statement
object로부터 property를 삭제한다. (변수나 함수에는 사용할 수 없다.)
① property의 값과 ② property 그 자체 두 가지 다 삭제한다.
typeof
typeof operand
typeof (operand)
괄호는 써도 되고 안 써도 된다.
operand는 문자열, 변수, 키워드, 객체이다.
변수/객체/함수/표현식의 type을 나타내는 string을 리턴한다.
- NaN의 데이터 타입은 number이다.
- array의 데이터 타입은 object이다.
- date의 데이터 타입은 object이다.
- null의 데이터 타입은 object이다.
- undefined 변수의 데이터 타입은 undefined이다.
typeof 62; // returns "number"
typeof true; // returns "boolean"
void
void expression
void (expression)
Relational operators (관계 연산자)
- operand(피연산자)들을 비교해서 불리언 값을 리턴한다.
in
propNameOrNumber in objectName
specify된 property가 specify된 object 안에 존재하면 true, 그렇지 않으면 false를 리턴한다.
propNameOrNumber - array index나 property 이름을 나타내는 string, numeric, or symbol expression.
objectName - object의 이름
// Arrays
var trees = ["redwood", "bay", "cedar", "oak", "maple"];
0 in trees; // returns true
3 in trees; // returns true
6 in trees; // returns false
"bay" in trees; // returns false (you must specify the index number,
// not the value at that index)
"length" in trees; // returns true (length is an Array property)
// built-in objects
"PI" in Math; // returns true
var myString = new String("coral");
"length" in myString; // returns true
// Custom objects
var mycar = { make: "Honda", model: "Accord", year: 1998 };
"make" in mycar; // returns true
"model" in mycar; // returns true
instanceof
objectName instanceof objectType
specify된 object가 specify 된 object 타입이라면 true를 리턴한다.
objectName - objectType과 비교할 object의 이름
objectType - Date나 Array같은 object 타입
런타임에 object의 타입을 컨펌하고 싶을 때 사용한다.
ex) when catching exceptions, you can branch to different exception-handling code depending on the type of exception thrown.
var theDay = new Date(1995, 12, 17);
if (theDay instanceof Date) {
// statements to execute
}
// true → if statement를 실행시킨다.
연산자 우선순위
< 출처 >
https://developer.mozilla.org/ko/docs/Web/JavaScript/Guide/Expressions_and_Operators
https://www.w3schools.com/jsref/jsref_operators.asp
'정리_창고' 카테고리의 다른 글
JavaScript - 정규표현식 (0) | 2020.07.08 |
---|---|
JavaScript - Number Methods 사전식 정리 (0) | 2020.07.08 |
JavaScript - Math Methods 사전식 정리 (0) | 2020.07.08 |
JavaScript - Global Methods 사전식 정리 (0) | 2020.07.08 |
JavaScript - String Methods 사전식 정리 (0) | 2020.07.05 |
댓글