본문 바로가기

JavaScript9

자바스크립트 기초 #5 | Function / Arrow function Function / Arrow function Function - 프로그램의 기본 구성 요소, 블록 - 재사용 가능 - 작업을 수행하거나 값 계산 1. Function declaration 함수 선언 - function name (param1, param2) {body ... return;} - one function === one thing - naming: doSomething, command, verb e.g. createCardAndPoint -> createCard, createPoint - js에서 함수는 객체 function printHello(){ console.log('Hello'); } printHello(); function log(message){ console.log(message.. 2021. 3. 13.
자바스크립트 기초 #4 | Operator 연산 반복문 Operator 1. String concatenation console.log('my' + 'name is sh'); // 문자열 + 문자열 console.log('1' + 2); // 문자열 + 숫자 console.log(`string literals : 1 + 2 = ${1 + 2}`); // string literals 2. Numeric oprators // 숫자 연산 console.log(1 + 1); // add console.log(1 - 1); // substract console.log(1 / 1); // divide console.log(1 * 1); // nultiply console.log(7 % 3); // remainder console.log(2 ** 5); //.. 2021. 2. 7.
자바스크립트 기초 #3 | Variable 입력-연산-출력 cpu에 최적화된 연산 메모리의 사용을 최소화 하는 것 중요 변수(Variable) let (Mutable Data Types) rw(read/write) 메모리의 값을 읽고 쓰기 가능 변수 선언 후 변경 가능 (es6에서 추가) const (contants/Immutable Data Types) read only 읽는 것만 가능 변수의 값을 바꿔야 할 이유가 없다면 웬만해선 const를 사용 변수 선언 후 변경 불가능 보안성 높음 코드 실수 방지 var 절대 사용 x 선언 전 값 할당, 출력 가능 유연한 사용이 가능하여 원래는 var를 사용했으나 var hoisting 등의 문제로 사용 xxxx block scope 없음 항상 global scope이기 때문에 메모리 많이 차지 hois.. 2021. 2. 7.
자바스크립트 기초 2 'use strict'; js 파일 가장 윗부분에 선언 정의되지 않은 변수도 문제없이 사용 가능한 것과 같이 비상식적인 코드를 사용할 수 있는 js에서 혼란을 막아줌 비정상적인 코드를 사용했을 경우 에러로 나타내주며, ecma 5에 use strict가 정의됨 ===== 자바스크립트 파일 연동 시 async와 defer async boolean 타입 설정하는 것 만으로도 true로 설정되어 어쩌고라 별로 defer 이게 좋음 2021. 2. 7.