What does "use strict"; line of code does in the function?

Tell us what’s happening:
I removed "use strict"; a line of code from the Function to see his effect but it doesn’t have any effect. on the function. when I run the code by deleting “use strict”; it works, so what does “use strict”; code does?

Your code so far

function printManyTimes(str) {
"use strict";

// Only change code below this line

const SENTENCE = str + " is cool!";
for (let i = 0; i < str.length; i+=2) {

// Only change code above this line


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/82.0.4068.4 Safari/537.36.

Challenge: Declare a Read-Only Variable with the const Keyword

Link to the challenge:

strict mode in javascript

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.
1 Like