DEV Community

Cover image for JavaScript Strict Mode
Bello Osagie
Bello Osagie

Posted on • Updated on

JavaScript Strict Mode


Brendan Eich knew it would be impossible to create a programming language without mistakes in 10 days, so he created a multi-paradigm type of language.

Multi-paradigm is a term in computer programming that allows different styles of programming. That is the ability to structure code in different ways.

The Multi-paradigm approach made JavaScript flexible and versatile. In fact, JavaScript at first was not created to last long, it was created to support Java to improve the users' experience on the web.

Java and JavaScript are two different programming languages even though JavaScript syntax initially was to look like Java

Over time, JavaScript began to evolve and new features were added to the language to overrule past mistakes. The big release or version of JavaScript was in 2015, called ECMAScript 2015. Ever since then JavaScript JavaScript releases new versions or updates every year.

The downside was mistakes made before ECMAScript 2015 by the JavaScript creators got stuck in the language forever. But there's a JavaScript mode or directive called use strict that disallows any past mistake code structure.


image.png


use strict

The directive looks like a string, "use strict" or 'use strict'. It is either located at the topmost of a script or the top of a function.

Although a JavaScript program or script that uses classes and modules enables 'use strict' automatically.

For example, an undeclared variable will lead to a bug when use strict is used in a program.

Undeclared Variable

'use strict';

name = 'Bello'; // ReferenceError: name is not defined
console.log(name);
Enter fullscreen mode Exit fullscreen mode

Declared Variable

'use strict';

const name = 'Bello';
console.log(name) // Bello
Enter fullscreen mode Exit fullscreen mode

Edit on Replit


Conclusion

It is a good practice to"use strict" mode at the top of a program (script) or the top of a function. In future articles, the line for "use strict" will be skipped.

Happy Coding!!!


Buy me a Coffee


TechStack Media | Bluehost

  • Get a website with a free domain name for 1st year and a free SSL certificate.
  • 1-click WordPress install and 24/7 support.
  • Starting at $3.95/month.
  • 30-Day Money-Back Guarantee.

Top comments (0)