js quiz 3 (46~70)

2025. 6. 10.·🎨 프론트엔드 공부/JS & TS

📌46. 객체의 참조 저장

let person = { name: 'Lydia' };
const members = [person];
person = null;

console.log(members); // [ { name: 'Lydia' } ]

 

객체를 변수에 할당하면 값 자체가 아닌, 참조(메모리 주소)가 저장된다

- members[0] 이 person과 같은 참조를 바라보고 있다가

- person = null 할당되어 person의 참조가 바뀌어도

- members[0] 이 애초에 바라보던 참조가 바뀌지 않는다

 

📌49. parseInt

const num = parseInt('7*6', 10); // 7

 

- 문자열의 첫 번째 유효한 10진수 숫자만 숫자로 변환된다

- *은 유효한 숫자가 아니라서 7까지만 변환됨

 

54. typeof undefined

(() => {
  let x = (y = 10);
})();

console.log(typeof x); // "undefined"
console.log(typeof y); // "number"

 

- x: undefined

- typeof null 은 "object" 이지만, typeof undefined 는 "undefined"

- y: 10 (global 객체에 할당됨)

 

📌56. Set 객체

const set = new Set([1, 1, 2, 3, 4]);

console.log(set); // {1, 2, 3, 4}

 

- Set 객체는 고유한 값들의 집합을 의미하므로, 이터러블을 넣으면, 고유한 값들만 Set에 담긴다

 

📌57. imported module

// counter.js
let counter = 10;
export default counter;
// index.js
import myCounter from './counter';

myCounter += 1;

console.log(myCounter); // Error

 

- imported module은 읽기 전용이므로, 수정하려고 하면 에러를 발생시킨다

 

📌58. delete 연산자

const name = 'Lydia';
age = 21;

console.log(delete name); // false
console.log(delete age); // true

 

delete

- 삭제에 성공하면 true, 실패하면 false 반환

- 전역 객체에 할당된 값은 delete로 제거할 수 있다

 

61. Object.defineProperty()

const person = { name: 'Lydia' };

Object.defineProperty(person, 'age', { value: 21 });

console.log(person); // {name: 'Lydia', age: 21}
console.log(Object.keys(person)); // ['name']

 

defineProperty()

- 새로운 프로퍼티를 추가하거나 기존 프로퍼티 수정 가능

- defineProperty로 추가한 프로퍼티는 기본적으로 enumerable 하지 않으며 수정도 불가

- 그리고 Object.keys() 메서드는 enumerable한 프로퍼티들만 배열로 만들어서 반환한다

 

📌62. JSON.stringify()

const settings = {
  username: 'lydiahallie',
  level: 19,
  health: 90,
};

const data = JSON.stringify(settings, ['level', 'health']);
console.log(data); // {"level":19,"health":90}

 

JSON.stringify()

- 2번째 인수에 replacer 전달 가능

- replacer 인수가 배열인 경우, 특정 프로퍼티만 직렬화

- 함수인 경우 모든 프로퍼티에 동작하며, 직렬화되는 값을 만듬, undefined를 반환하면 해당 프로퍼티는 배제

 

📌66. class extends

// 성공적으로 Dog 클래스를 확장하는 생성자 함수 번호 고르기

class Dog {
  constructor(name) {
    this.name = name;
  }
};

class Labrador extends Dog {
  // 1
  constructor(name, size) {
    this.size = size;
  }
  // 2
  constructor(name, size) {
    super(name);
    this.size = size;
  }
  // 3
  constructor(size) {
    super(name);
    this.size = size;
  }
  // 4
  constructor(name, size) {
    this.name = name;
    this.size = size;
  }

};

 

 

super()

- 부모 클래스의 생성자 함수를 호출한다

- 따라서 super() 호출 전에는 this로 부모 클래스의 멤버를 참조할 수 없다 (ReferenceError 발생)

- super(변수명) 을 통해 부모 클래스의 생성자 함수에 인수를 전달할 수 있다

 

📌67. imported module

// index.js
console.log('running index.js');
import { sum } from './sum.js';
console.log(sum(1, 2));

// sum.js
console.log('running sum.js');
export const sum = (a, b) => a + b;

/* 결과
'running sum.js'
'running index.js'
3
*/

 

 

- imported module들이 먼저 프리파싱되므로, sum.js 가 먼저 실행된다

- CommonJS의 require()는 이와 반대로 imported module을 나중에 실행

 

📌68. symbol 비교

console.log(Number(2) === Number(2)); // true
console.log(Boolean(false) === Boolean(false)); // true
console.log(Symbol('foo') === Symbol('foo')); // false

 

Symbol

- 모든 Symbol은 고유하다

- Symbol에 전달되는 인수는 description

 

 

참고

https://javascript-questions.vercel.app/

'🎨 프론트엔드 공부/JS & TS' 카테고리의 다른 글
  • js quiz 5 (101~131)
  • js quiz 4 (71~100)
  • js quiz 2 (18~45)
  • js quiz 1 (1~17)
지식물원
지식물원
지식이 자라는 식물원!
  • 지식물원
    지식물원
    지식물원
  • 전체
    오늘
    어제
    • 분류 전체보기 (516)
      • 🎨 프론트엔드 공부 (253)
        • JS & TS (92)
        • HTML & CSS (22)
        • React & Next (49)
        • Vue & Nuxt (22)
        • 기타 (68)
      • 🤓 기술 학습 & 공부 기록 (116)
        • Node.js (0)
        • Python (37)
        • 백엔드 (0)
        • 딥러닝 (1)
        • 컴퓨터 일반 (72)
        • 개발 인프라 (6)
      • 👨‍💻 프로젝트 경험 (6)
        • Work (0)
        • Toy (6)
      • ⚙️ 개발 팁 & 노하우 (21)
        • 프론트엔드 (6)
        • 기타 (15)
      • ☕️ 커리어 & 인터뷰 준비 (88)
        • 코딩 테스트 (88)
      • 📰 기술 트렌드 & 생각 정리 (4)
      • 📚 기타 (25)
        • 마케팅 (15)
        • 비개발서적 (10)
  • 블로그 메뉴

    • 태그
  • 링크

  • 공지사항

    • 모바일 접속 시 코드 하이라이팅 깨질 때
  • 인기 글

  • hELLO· Designed By정상우.v4.10.3
지식물원
js quiz 3 (46~70)
상단으로

티스토리툴바