Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


"use strict"

Do pro programmers code with strict mode on ? Can you explain strict mode?

2 Answers

Jennifer Nordell
Jennifer Nordell
Treehouse Teacher

Hi there, ah11 ! I received your request for assistance. Yes, I do tend to use "strict mode". This was introduced into new versions of JavaScript. The idea here is to keep your code as "safe" as possible. In strict mode, you cannot use a variable that is not previously declared, you cannot use names that have already been determined will be keywords in future iterations of JavaScript, you cannot delete a function (delete myFunction), nor a variable, you cannot delete a prototype from an object and a multitude of other things. This is entirely for security reasons and to help keep you from inadvertently doing something with your code that you never meant to do.

Imagine for a moment that you used a variable that would then later become a keyword in JavaScript 3 weeks down the line. All of your code would probably break and it might be a bit before you notice it. There are lots of examples on what you can and cannot do in strict mode. I highly suggest you take a look at the documentation here.

Hope this helps! :sparkles:

Michael Hulet
Michael Hulet
47,912 Points

These are all very good points, and to add onto it, a lot of our stack where I work is in JavaScript, and I don't think there's a single file that isn't marked with "use strict"

Zhaopeng Wang
.a{fill-rule:evenodd;}techdegree seal-36
Zhaopeng Wang
Full Stack JavaScript Techdegree Graduate 32,210 Points
  • Yes, people do use strict mode in a production environment, because JS gives too much freedom and something would cause problems.
  • one of the main reason is that it forces you to declare the variable before actually using it. And it will remind you to put var in front, therefore, it helps not to mess up with the scope.
  • ESLint is also recommended in production environment