Strict Mode

3 minutes
Share the link to this page
Copied
  Completed
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.

Transcript

Hello, in this JavaScript video, I am going to show you strict mode. And JavaScript is a pre leased language. So he makes so two mistakes that most other languages really penalize you for and just, you know, throw an error prevent you from running the application JavaScript, just like yeah, you know, really ugly know what you mean. So I'll just fix it. So if you want like a really sort of one of them sad, secure, but more just a more conformed, I would say a better way of coding. Because you know, when you just deal in JavaScript, the most points, okay, is when you start going to other languages.

That's when the problem occurs if you're going from JavaScript, so to enable strictmode Actually, let me show you we've got this you know, variable created here from a previous video. And if I show you something and go to console, you know, it's all fine if I remove this I save it, and I reload it, I think, you know, it is still fine. And this is an example of one of those loose things I was talking about. If you don't use the keyword bar before variable, and you don't have strict mode enabled, you're just declare it as a variable. If this is the first time you've seen it, if instead you actually put this quotation marks, use semi colon, say that now and if you reload, as you can see it frozen there, I think uncaught reference error, or five is not defined. But if I go back ball I didn't think that error now disappears.

So I would say just make sure you just use strict mode, your make sure that you are creating, you know, essentially good code Another reason is so this is an example of variables. Maybe I've created this variable. And let's just say I'm not using strict mode. And maybe I want to modify it. So actually, I'm gonna rename it to, to hello world. For example, at the moment, this should run fine, no errors.

But if I were to not let the phone and reassign it, hello, and I'd put Well, maybe I'll put this, you know, it's slightly renamed differently, not equal eight instead. Save it. Refresh. As you can see, there's no error. So I made a mistake in typing it and it hits here, if they Hello worried was never created as a variable that's just created. But if I use strict mode, it will throw an error thing it does not exist and I immediately say, oh, I've, you know, try to use the wrong variable I, you know, made a mistake was typing and this will help prevent so many errors you will always miss type stuff in coding.

So that's it for strict mode. As usual. If you have any questions, feel free to pop me a message. There'll be the GitHub link which provides you with all the source code, and I look forward to seeing you in the next video.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.