DEV Community

Chokri K'
Chokri K'

Posted on • Originally published at khalifa.tn on

 

What ‘use strict’ means for in JavaScript

“strict mode”;

It’s a ECMAScript 5 feature that prevents certain actions from being taken and throws more exceptions in a JavaScript code.

The strict mode is necessary if you have a complex code to write. It introduces better error-checking, If you have a calculating algorithm.

Without this mode you can write console.log(Infinity = 0) and there is no problem with that. This will return 0 as inspected and Error “TypeError: “Infinity” is read-only”

We can use this feature into a function. For example:

// Non-strict code... (function(){ "use strict"; // Define your library strictly... })(); // Non-strict code...

But, if you activate it you’ll see a lot of problems on the console. To avoid that, try to write a clean code.

The post What ‘use strict’ means for in JavaScript appeared first on C.Khalifa.

Top comments (0)

11 Tips That Make You a Better Typescript Programmer

typescript

1 Think in {Set}

Type is an everyday concept to programmers, but it’s surprisingly difficult to define it succinctly. I find it helpful to use Set as a conceptual model instead.

#2 Understand declared type and narrowed type

One extremely powerful typescript feature is automatic type narrowing based on control flow. This means a variable has two types associated with it at any specific point of code location: a declaration type and a narrowed type.

#3 Use discriminated union instead of optional fields

...

Read the whole post now!