본문 바로가기

전체 글125

lexical grammer/어휘문법 명령문 끝에 자동으로 세미콜론을 추가 1. empty statement 2. let, const variable statement 3. import, exprt, module declaration 4. expression statement 5. debugger 6. continue, break, throw 7. return 그 외 1. 문법에서 허용하지 않는 행 종결 또는 "}"가 나타날 때 앞에 세미콜론을 삽입함. { 1 2 } 3 // is transformed by ASI into { 1 2 ;} 3; 2. 여기서 ++는 b와 ++사이에 줄 종결자가 발생하기 때문에 변수 b에 적용되는 후위연산자로 취급되지 않음. a = b ++c // is transformend by ASI into a = b; .. 2022. 1. 24.
First-class Function A programming language is said to have First-class functions when functions in that language are treated like any other variable. For example, in such a language, ① a function can be passed as an argument to other functions, ② can be returned by another function and ③can be assigned as a value to a variable. ① a function can be passed as an argument to other functions function sayHello() { retur.. 2022. 1. 24.
closure A closure is the combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment). In other words, a closure gives you access to an outer function’s scope from an inner function. In JavaScript, closures are created every time a function is created, at function creation time. Lexical scoping : 프로그램 내에서 선언된 변수의 위치에 의하여 그 변수가 사용될 범위가 결정되는것. fu.. 2022. 1. 23.
변수, type, 할당, return script defer로 작성하는 것이 제일 좋음. HTML을 parsing하는 동안 다운받고 페이지가 준비되면 실행함. 여러개일 경우 순서대로 실행됨. 자바스크립트에서 중요한것 : 입력/연산/출력 변수(var는 blcok scope가 없음. 사용하지 않음) 1. let (mutable) 2. const 값이 정해지면 바꿀 수 없음. (immutable) variable type 1. primitive, single item : number, string, boolean, null, undefined, symbol 2. object(primitive type을 제외하고 모두), box container 3. function, first-class function boolean false : 0, null.. 2022. 1. 23.
indexOf() let ex = 'hello world'; console.log(ex.indexOf('e')); indexOf()는 해당 문자열이 몇번 인덱스에 있는지 찾아줌. 만약 문자열에 존재하지 않을 경우 -1을 반환함. let strike = 0; let ball = 0; for(let i=0; i -1){ if(index === i){ strike += 1; } else{ ball += 1; } } } answer의 1번째 인덱스의 문자열이 myNumber의 문자열에 존재하지 않으면 -1이 index에 할당, 존재하면 1이상의 수가 할당됨. 만약 index가 -1보다 크면(그러면 answer의 문자열 중 하나(혹은 그 이상) 와 myNumber의 문자열 중 하나(혹은 그 이상)이 일치한다는 것을 의미) 그 중 .. 2022. 1. 15.
기본개념5. Object 오브젝트 구분 1. Built-in Object 1) 미리 만들어 놓은 오브젝트 2) Built-in Number/String 오브젝트 2. Native Object 1) JS 스펙에서 정의한 오브젝트 2) 빌트인 오브젝트를 포함함 3) JS코드를 실행할 때 만드는 오브젝트(Argument 오브젝트) 3. Host Object 1) 빌트인, 네이티브 오브젝트를 제외한 오브젝트(window, DOM 오브젝트) 2) JS는 호스트 환경에서 브라우저의 모든 요소기술을 연결하고 융합하며 이를 제어 Object 생성 방법 var abc = {}; // var abc=Object()와 같음. Object의 인스턴스 생성. {}오브젝트 리터럴이라고 부름. 함수 호출방법 : Object.create(); 메소드 호출방.. 2022. 1. 9.