Operator & Expression
in
Description
in
μ°μ°μλ λͺ
μλ μμ±μ΄ κ°μ²΄μ μ‘΄μ¬νλ©΄ true
λ₯Ό λ°νν©λλ€.
Syntax
μμ± in κ°μ²΄λͺ
- μμ±
- μμ±μ μ΄λ¦μ΄λ λ°°μ΄μ μΈλ±μ€λ₯Ό λ»νλ λ¬Έμμ΄ λλ μμ κ°μ λλ€.
- κ°μ²΄λͺ
- κ°μ²΄μ λͺ μΉ
Example
var arrayObj = ['a', 'b', 'c'];
console.log(3 in arrayObj); // false
console.log(0 in arrayObj); // true
console.log('a' in arrayObj); // false
console.log('length' in arrayObj); // true
var color1 = new String('green');
console.log('length' in color1); // true
var color2 = 'Red';
console.log('length' in color2); // false
// color2 λ String κ°μ²΄κ° μλκΈ° λλ¬Έμ μ€λ₯λ₯Ό λ°μν¨
String
μμ±μλ‘ λ§λ€μ΄μ§ λ¬Έμμ΄μ λͺ
μν μ μμ§λ§ λ¬Έμμ΄ λ¦¬ν°λ΄μ λͺ
μν μ μλ€
console.log('toString' in {}); // true
νλ‘ν νμ
체μΈμ μνμ¬ μ κ·Ό κ°λ₯ν μμ±μ true
λ₯Ό λ°νν©λλ€.
instanceof
Description
instanceof
μ°μ°μλ μμ±μμ prototype
μμ±κ³Ό λ¬ΆμΈ νλ‘ν νμ
μ κ°μ§ μ€λΈμ νΈμΈμ§ νμΈν©λλ€.
Syntax
object instanceof constructor
- object
- ν μ€νΈ λμμΈ μ€λΈμ νΈ
- constructor
- ν μ€νΈν ν¨μ (νλ‘ν νμ μ€λΈμ νΈ)
Example
function C() {};
var obj = new C();
console.log(obj instanceof C); // true
function Car(make, model, year) {
this.make = make;
this.model = model;
this.year = year;
}
var auto = new Car('Honda', 'Accord', 1998);
console.log(auto instanceof Car); // true
console.log(auto instanceof Object); // true
typeof
Description
typeof
μ°μ°μλ νΌμ°μ°μ νμ
μ κ°λ₯΄ν€λ λ¬Έμμ΄μ λ°νν©λλ€.
νμ | κ²°κ³Ό |
---|---|
Undefined | "undefined" |
Null | "object" |
String | "string" |
Number | "number" |
Array | "object" |
Boolean | "boolean" |
Function Object | "function" |
other Object | "object" |
Syntax
typeof νΌμ°μ°μ
Example
console.log(typeof 100) // number
console.log(typeof '100') // string
console.log(typeof 'abc') // string
console.log(typeof []) // object
console.log(typeof undefined) // number
console.log(typeof function foo() {}) // function
delete
Description
delete
μ°μ°μλ μ€λΈμ νΈμ μμ±μ μμ νλ€.
Syntax
delete object[.property]
- object
- μ€λΈμ νΈμ μ΄λ¦ λλ μ€λΈμ νΈμ ννμ
- property
- μμ νκ³ μ νλ μμ±
Example
var Employee = {
age: 28,
name: 'abc'
designation: 'developer'
};
console.log(delete Employee.name); // true
console.log(delete Employee.age); // true
// ν΄λΉ νλ‘νΌν°κ° μ‘΄μ¬νμ§ μμ trueλ₯Ό 리ν΄ν©λλ€.
console.log(delete Employee.salary); // true
`delete`μ°μ°μμ μ¬μ©μ μ μμ¬ν.
- μ‘΄μ¬νμ§ μλ μμ±μ μμ νλ €κ³ νλ©΄ μ무 μμ
μμ΄
true
λ₯Ό λ°ν - μ€λΈμ νΈμ νλ‘ν νμ
체μΈκ³Ό κ°μ μμ±μ΄ μλ€λ©΄
delete
λ‘ μμ νμ νλ‘ν νμ μ²΄μΈ νλ‘νΌν° μ¬μ©κ°λ₯ var
λ‘ μ μΈλ νλ‘νΌν°λ μμ λΆκ°
β Global Object