use-strict - jslint vs jshint - What does “use strict” do in JavaScript, and what is the reasoning behind it?

npm jslint / javascript / syntax / jslint

Recently, I ran some of my JavaScript code through Crockford's JSLint, and it gave the following error:

Mark Rogers



Answer #1
for (i of [1,2,3]) console.log(i)
    
// output:
// 1
// 2
// 3
'use strict';
for (i of [1,2,3]) console.log(i)

// output:
// Uncaught ReferenceError: i is not defined
String.prototype.test = function () {
  console.log(typeof this === 'string');
};

'a'.test();

// output
// false
String.prototype.test = function () {
  'use strict';
  
  console.log(typeof this === 'string');
};

'a'.test();

// output
// true