> For the complete documentation index, see [llms.txt](https://seula00027.gitbook.io/til/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://seula00027.gitbook.io/til/vanillacoding/04.quiz.md).

# 04.quiz

**참조위치는 그대로 두고 안에 있는 내용을 비우기**

```javascript
var something = [1, 2, 3, 4, 5];
something.length = 0;
```

**결과는?**

```javascript
var a = {};
var output = {function() {
  delete x;
  return x;
}}();

console.log(a);
```

delete는 객체에서 key, value를 지울때 사용한다. 용도가 잘못쓰여져 있다.

**결과는?**

```javascript
var Employee = {
    company: 'xyz'
}

var emp1 = Object.create(Employee);
// emp1 = {}
// __proto__ : company: 'xyz';
delete emp1.company;
// emp1에 있는 company를 지울려고 하는데 emp1에 없기 때문이다. 
// delete emp1.__proto__.company
// 이렇게 하면 Employee에 있는게 지워진다. 소름.. 
console.log(emp1.company);
```

**객체 만들기**

1. 'new' 키워드
2. 오브젝트 리터럴 {}
3. Object.create();

**this가 무엇인가?**

```javascript
function myFunc() {
  console.log(this.message);
}
myFunc.message = 'Hi John';

console.log(myFunc()) // this는 window고 console엔 undefined
```

**What will be logged?**

```javascript
function Person(names, age){
  this.names = name || "John";
  this.age = age || 24;
  this.displayName = function () {
    console.log(this.names);
  };
}

Person.names = "John2";
Person.displayName = function () {
  console.log(this.names);
};

var person1 = new Person("John3");
person1.displayName();
Person.displayName();
```

```javascript
function passWordMngr() {
  var password = '12345678';
  this.userName = 'John';
  return {
    pwd: password
  };
}
var userInfo = passWordMngr();
console.log(userInfo.pwd); // '12345678'
console.log(userInfo.userName); // undefined
```
