반응형

드림코딩엘리 4

Array

JS에서는 boolean, number, string, null, undefined을 제외하면 모두 객체라는 특징이 있다. 배열은 Array 생성자로 생성된 Array 타입의 객체이며 프로토타입 객체는 Array.prototype이다. 1. declaration const arr1 = new Array(); const arr2 = [1,2]; 2. index position const fruits =['a','b']; console.log(fruits); // a, b console.log(fruits[0]);// a | 대괄호 안에 숫자를 기입하면 이를 index로 인식한다. console.log(fruits[1]);// b console.log(fruits[fruits.length - 1]);//배열..

IT/JS 2021.05.20

Function

1. function 함수는 object의 일종이다. JS에서는 타입 정의를 따로 하지 않기 때문에 이것이 숫자인지 문자열인지 난해할 수 있다. 따라서 TS(TypeScript)를 활용하여 정확하게 변수의 데이터타입을 지정해주어야한다. TS활용 예시) function log(x: string): number {} // 함수에 타입을 정하는 방식 일반적인 함수 선언 function log(x){ console.log(x); } ​ 2. parameters primitive parameters: passed by value object parameters: passed by reference function changename(x){ x.name='coder'; } const hty = {name:'hty'..

IT/JS 2021.05.20

Class

JS Classes es6에서 소개되었으며, 기존 js에 문법적으로 추가된 것이다(완전히 새로운 것이 아님). 이를 syntactical sugar이라고 한다. 클래스는 붕어빵 기계의 틀과 같다고 할 수 있다. 이 틀에 반죽과 팥이라는 data를 넣었을때, 만들어진 붕어빵은 Object와 같다고 할 수 있다. 즉 클래스를 활용하여 다양한 오브젝트를 만들 수 있는 것이다(단팥, 피자, 초코 붕어빵 등등..). 클래스의 이름은 대문자로 시작하는 규칙이 있다. class Person{ //constructor constructor(name,age){ //field this.name=name; //this:생성된 오브젝트의 name this.age=age; } //methods speak(){ console.l..

IT/JS 2021.05.20

Operator, Control flow statement

1. string concatenation 문자열 연결 문자열과 숫자 연결의 경우 + 연산자를 이용 console.log('my'+'cat'); console.log('1'+2);​ 변수를 출력하는 경우 ( ` ` )안에 위치 console.log(`string literals: 1+2 = ${1 + 2}`); console.log('hatae\'s \nbook');​ ( ' ' )안에 '를 문자열로 입력해야하는 경우 \사용 console.log('hatae\'s \nbook');​ 2. numeric operator 사칙연산 및 거듭제곱(**), 나머지(%)를 활용 console.log(1+1); console.log(2**2);​ 3. increment and decrement operators le..

IT/JS 2021.05.20
반응형