본문 바로가기

개발/Javascript

(33)
코멘트(Comments) 코멘트(Comments)Use /** ... */ for multi-line comments. Include a description, specify types and values for all parameters and return values.복수행의 코멘트는 /** ... */ 을 사용해 주십시오. 그 안에는 설명과 모든 파라메터, 반환값에 대해 형이나 값을 기술해 주십시오.// bad // make() returns a new element // based on the passed in tag name // // @param {String} tag // @return {Element} element function make(tag) { // ...stuff... return element; } /..
블록(Blocks) 블록(Blocks)Use braces with all multi-line blocks.복수행의 블록에는 중괄호 ({}) 를 사용해 주십시오.// bad if (test) return false; // good if (test) return false; // good if (test) { return false; } // bad function() { return false; } // good function() { return false; }If you're using multi-line blocks with if and else, put else on the same line as your if block's closing brace.복수행 블록의 if 와 else 를 이용하는 경우 else 는 if ..
프로퍼티(Properties) 프로퍼티(Properties)Use dot notation when accessing properties.프로퍼티에 억세스하는 경우는 점 . 을 사용해 주십시오.const luke = { jedi: true, age: 28, }; // bad const isJedi = luke['jedi']; // good const isJedi = luke.jedi;Use subscript notation [] when accessing properties with a variable.변수를 사용해 프로퍼티에 억세스하는 경우는 대괄호 [] 를 사용해 주십시오.const luke = { jedi: true, age: 28, }; function getProp(prop) { return luke[prop]; } const..
Arrow함수(Arrow Functions) Arrow함수(Arrow Functions)When you must use function expressions (as when passing an anonymous function), use arrow function notation.(무명함수를 전달하는 듯한)함수식을 이용하는 경우 arrow함수 표기를 이용해 주십시오.Why? It creates a version of the function that executes in the context of this, which is usually what you want, and is a more concise syntax.왜? arrow함수는 그 context의 this 에서 실행하는 버전의 함수를 작성합니다. 이것은 통상 기대대로의 동작을 하고, 보다 간..
조건식과 등가식(Comparison Operators & Equality) 조건식과 등가식(Comparison Operators & Equality)Use === and !== over == and !=.== 이나 != 보다 === 와 !== 을 사용해 주십시오.Conditional statements such as the if statement evaluate their expression using coercion with the ToBooleanabstract method and always follow these simple rules:Objects evaluate to trueUndefined evaluates to falseNull evaluates to falseBooleans evaluate to the value of the booleanNumbers evalu..
Hoisting Hoistingvar declarations get hoisted to the top of their scope, their assignment does not. const and let declarations are blessed with a new concept called Temporal Dead Zones (TDZ). It's important to know why typeof is no longer safe.14.1 var 선언은 할당이 없이 스코프의 선두에 hoist 됩니다. const 와 let 선언은Temporal Dead Zones (TDZ) 라고 불리는 새로운 컨셉의 혜택을 받고 있습니다. 이것은 왜 typeof 는 더이상 안전하지 않은가를 알고있는 것이 중요합니다.// we know ..
변수(Variables) 변수(Variables)Always use const to declare variables. Not doing so will result in global variables. We want to avoid polluting the global namespace. Captain Planet warned us of that.변수를 선언 할 때는 항상 const 를 사용해 주십시오. 그렇게 하지 않으면 글로벌 변수로 선언됩니다. 글로벌 namespace 를 오염시키지 않도록 캡틴플래닛도 경고하고 있습니다.// bad superPower = new SuperPower(); // good const superPower = new SuperPower();Use one const declaration per vari..
이터레이터와 제너레이터(Iterators and Generators) Don't use iterators. Prefer JavaScript's higher-order functions like map() and reduce() instead of loops like for-of.iterators를 이용하지 마십시오. for-of 루프 대신에 map() 과 reduce() 와 같은 JavaScript 고급함수(higher-order functions)를 이용해 주십시오.Why? This enforces our immutable rule. Dealing with pure functions that return values is easier to reason about than side-effects.왜? 고급함수는 immutable(불변)룰을 적용합니다. side effect..