TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

JavaScript Strict Mode

JavaScript Strict Mode with javascript, innerhtml, tutorials, examples, html, dom, css, tags, events, validation, object, loop, array, document etc.

<< Back to JAVASCRIPT

JavaScript Strict Mode

Being a scripting language, sometimes the JavaScript code displays the correct result even it has some errors. To overcome this problem we can use the JavaScript strict mode.

The JavaScript provides "use strict"; expression to enable the strict mode. If there is any silent error or mistake in the code, it throws an error.

Note - The "use strict"; expression can only be placed as the first statement in a script or in a function.

JavaScript use strict Example

Example 1

Let's see the example without using strict mode.

<script>
x=10;
console.log(x);
</script>

Output:

Here, we didn't provide the type of variable. Still we are getting an output.

Javascript Strict Mode

Let's see the same example by enabling the strict mode.

<script>
"use strict";
x=10;
console.log(x);
</script>

Output:

Now, it will throw an error as the type of x is not defined.

Javascript Strict Mode

Example 2

Let's see one more example to print sum of two numbers.

<script>
console.log(sum(10,20));
function sum(a,a)
{
"use strict";
return a+a;
}
</script>

Output:

Here, an error occurs as we use duplicate elements.

Javascript Strict Mode
Next TopicJavaScript Promise




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf