본문 바로가기

전체 글

(85)
JS - object JS 강의 필기 + 추가 object { key : value } a collection of related data and/or functionality Nearly all objects in JS are instances of the class Object object 만드는 방식 2가지 const obj1 = {}; // 'object literal' syntax const obj2 = new Object(); // 'object constructor' syntax property 추가하기 const ellie = { name: 'ellie', age: 4 }; // object 생성 ellie.hasJob = true; // property 추가 console.log(ellie.hasJob); /..
JS - class JS 강의 필기 + 추가 object-oriented programming class: template 개념. fields(속성)과 method(행동)으로 이루어짐 object: an instance of a class constructor: 생성자. 이를 통해서 object를 만들 때 필요한 데이터를 전달 class Person { constructor(name, age) { // fields this.name = name; this.age = age; } speak() { // method console.log(`${this.name}: hello!`); } } const phin = new Person('phin', 30); // object 생성 console.log(phin.name); cons..
JS - function JS 강의 필기 + 추가 function a fundamental building block in the program subprogram can be used multiple times performs a task or calculates a value function declaration function name( params ) { body... return; } prefer to make one function does one thing naming: doSth (command/verb-like) function is object in JS // function without params. body에서 return undefined; 가 생략된 것 function printHello() { con..
JS - operator JS 강의 필기 + 추가 dynamic typing 때문에 string concatenation 주의해야 됨 console.log('my' + ' cat'); // my cat console.log('1' + 2); // 12 numeric operators add + subtract - divide / multiply * remainder % exponentitation ** Increment and decrement operators ++preIncrement, postIncrement++ --preDecrement, postDecrement-- assignment operators let x = 3; let y = 6; x += y; // x = x + y x -= y; x *= y; x /= y;..
JS - variable JS 강의 필기 + 추가 'use strict'; added in ES5. use this for Vanilla JS. 맨 위에 넣기. Variable declaration 1. constant: read-only. immutable. 2. let: mutable. added in ES6. problem: IE 지원 안 됨. 해결: ES6로 개발한 뒤 BARBEL에서 변환해서 배포 3. var: had used until ES5. don't ever use this. problems var hoisting(move declaration from bottom to top) has no block scope Datatype 1. Immutable: primitive types, frozen objects 2..