Skip to content

Instantly share code, notes, and snippets.

@jinsangYoo
Last active January 9, 2019 16:04
Show Gist options
  • Save jinsangYoo/8dba48a9876ab8597b493bd1880a8851 to your computer and use it in GitHub Desktop.
Save jinsangYoo/8dba48a9876ab8597b493bd1880a8851 to your computer and use it in GitHub Desktop.
Strict Mode 써야 하는 이유

Strict Mode is a new feature in ECMAScript 5 that allows you to place a program, or a function, in a “strict” operating context. This strict context prevents certain actions from being taken and throws more exceptions.

Strict Mode는 ECMAScript 5 버전에 있는 새로운 기능으로써, 당신의 프로그램 또는 함수를 엄격한 운용 콘텍스트 안에서 실행시킬 수 있게끔 합니다. 이 엄격한 콘텍스트는 몇가지 액션들을 실행할 수 없도록 하며, 좀 더 많은 예외를 발생시킵니다.

Strict mode helps out in a couple ways: It catches some common coding bloopers, throwing exceptions. It prevents, or throws errors, when relatively “unsafe” actions are taken (such as gaining access to the global object). It disables features that are confusing or poorly thought out.

Strict Mode는 몇가지 면에서 도움이 되는데: 흔히 발생하는 코딩 실수를 잡아내서 예외를 발생시킵니다. 상대적으로 안전하지 않은 액션이 발생하는 것을 방지하거나 그럴 때 예외를 발생시킵니다. 예를 들자면 전역객체들에 접근하려 한다거나 하는 것들이겠지요. 혼란스럽거나 제대로 고려되지 않은 기능들을 비활성화시킵니다.

사용 방법

js 상단 또는 함수내부에

"use strict";
var v = "Hi!  I'm a strict mode script!";

function strict(){
  // Function-level strict mode syntax
  'use strict';
  function nested() { return "And so am I!"; }
  return "Hi!  I'm a strict mode function!  " + nested();
}

function notStrict() { return "I'm not strict."; }

출처

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment