Jim Lynch Codes
  • Blog
  • About Jim

Writings about one coder's stories & experiences.

What Does 'use strict' Mean? 

2/13/2016

0 Comments

 
While looking at some examples I've seen that early on in the code there  will sometimes be a line that simply says "use strict"; which can be confusing to a beginner trying to understand every line. A lot of times "people will ask, what does this mean?" and kind of get shooed off with a "just do it" response. Here I'll try to explain some of what the difference is between doing it and not.

ES5 Strict Mode 

Strict Mode is a boolean "mode" for ECMAScript 5 that affects how your Javascript code is interpreted. It's defaults to false (strict mode off), but by including the line 'use strict'; it is toggled to true strict mode on). Strict mode is basically a subset of normal Javascript that prevents you from using generally accepted to be unreliable features of Javascript that were never fixed / removed. The main points are:
  • Assignment to an undeclared variable isn't allowed. Normally, assignment to an undeclared variable sets it in the global scope which is generally accepted as very bad so this is a great feature for strict mode to have.
  • Trying to delete things that cannot be deleted throws an error in strict mode (silently fails normally).
  • eval (cannot be reassigned, overridden, or used as a variable or property name and can't introduce new variables to the scope. (We've seen before how there are better choices than using eval() for general parsing).
  • The with keyword is removed in strict mode (because it is seen as having many bad characteristics).
Developers don't want their underlying platform itself to be buggy. You want to know that if something is not working, it's your fault. Fix something. By using strict mode you'll be much on a much safer path with a higher likelihood for success. 
0 Comments

Your comment will be posted after it is approved.


Leave a Reply.

    ​Author

    Picture
    The posts on this site are written and maintained by Jim Lynch. About Jim...
    Picture
    Follow @JimLynchCodes
    Follow @JimLynchCodes

    Categories

    All
    Actionscript 3
    Angular
    AngularJS
    Automated Testing
    AWS Lambda
    Behavior Driven Development
    Blockchain
    Blogging
    Business Building
    C#
    C / C++
    ClojureScript / Clojure
    Coding
    Community Service
    CS Philosophy
    Css / Scss
    Dev Ops
    Firebase
    Fitness
    Flash
    Front End
    Functional Programming
    Git
    Go Lang
    Haskell
    Illustrations
    Investing
    Java
    Javascript
    Lean
    Life
    Linux
    Logic Pro
    Music
    Node.js
    Planning
    Productivity
    Professionalism
    Python
    React
    Redux / Ngrx
    Refactoring
    Reusable Components
    Rust
    Security
    Serverless
    Shell Scripting
    Swift
    Test Driven Development
    Things
    TypeScript
    Useful Sites
    Useful Tools
    Video
    Website Development
    WebStorm
    Writing

    Archives

    March 2023
    August 2021
    February 2021
    January 2021
    October 2020
    September 2020
    May 2020
    April 2020
    February 2020
    January 2020
    December 2019
    October 2019
    September 2019
    August 2019
    July 2019
    June 2019
    May 2019
    April 2019
    March 2019
    February 2019
    January 2019
    December 2018
    November 2018
    October 2018
    September 2018
    August 2018
    June 2018
    May 2018
    April 2018
    March 2018
    February 2018
    January 2018
    December 2017
    November 2017
    October 2017
    September 2017
    August 2017
    July 2017
    May 2017
    April 2017
    March 2017
    February 2017
    January 2017
    December 2016
    November 2016
    October 2016
    September 2016
    August 2016
    July 2016
    June 2016
    May 2016
    April 2016
    March 2016
    February 2016
    January 2016
    December 2015
    November 2015
    October 2015

    RSS Feed

  • Blog
  • About Jim
JimLynchCodes © 2023