Questions tagged [use-strict]

According to Mozilla Developer Network, ECMAScript 5's strict mode is a way to opt in to a restricted variant of JavaScript. Strict mode isn't just a subset: it intentionally has different semantics from normal code.

According to Mozilla Developer Network, ECMAScript 5's strict mode is a way to opt in to a restricted variant of JavaScript. Strict mode isn't just a subset: it intentionally has different semantics from normal code.

100 questions
8421
votes
31 answers

What does "use strict" do in JavaScript, and what is the reasoning behind it?

Recently, I ran some of my JavaScript code through Crockford's JSLint, and it gave the following error: Problem at line 1 character 1: Missing "use strict" statement. Doing some searching, I realized that some people add "use strict"; into their…
Mark Rogers
  • 96,497
  • 18
  • 85
  • 138
226
votes
1 answer

How is the 'use strict' statement interpreted in Node.js?

I have started to explore the Node.js and wrote many demo web application, to understand the flow of Node.js, Express.js, jade, etc.. But one thing I came across recently, is the statement "use strict" as the first line inside every function and…
user2713270
98
votes
4 answers

Why is "this" in an anonymous function undefined when using strict?

Why is this in an anonymous function undefined when using javascript in strict mode? I understand why this could make sense, but I couldn't find any concrete answer. Example: (function () { "use strict"; this.foo = "bar"; // *this* is…
T. Junghans
  • 11,385
  • 7
  • 52
  • 75
66
votes
2 answers

Benefits of "Use Strict" in JS

What are the additional benefits of "use strict" other than preventing bad coding? For instance, does it allow the script to run faster because the interpreter knows the code its optimized?
TMacGyver
  • 1,281
  • 3
  • 12
  • 27
57
votes
5 answers

How do you find out the caller function in JavaScript when use strict is enabled?

Is it possible to see the callee/caller of a function when use strict is enabled? 'use strict'; function jamie (){ console.info(arguments.callee.caller.name); //this will output the below error //uncaught TypeError: 'caller',…
Jamie Hutber
  • 26,790
  • 46
  • 179
  • 291
53
votes
16 answers

How to remove global "use strict" added by babel

I'm using function form of "use strict" and don't want global form which Babel adds after transpilation. The problem is I'm using some libraries that aren't using "use strict" mode and it might throw error after scripts are concatenated
ani h
  • 531
  • 1
  • 4
  • 7
32
votes
10 answers

Is there a need for a "use strict" Python compiler?

There exist static analysis tools for Python, but compile time checks tend to be diametrically opposed to the run-time binding philosophy that Python embraces. It's possible to wrap the standard Python interpreter with a static analysis tool to…
cdleary
  • 69,512
  • 53
  • 163
  • 191
28
votes
4 answers

AngularJS controllers and "use strict"

I recently started using JSHint and it is requiring me to use the function form of "use strict". Since then, AngularJS throws an error: "Error: Argument 'webAddressController' is not a function, got undefined" When I remove the function form of "use…
Chris Bier
  • 14,183
  • 17
  • 67
  • 103
25
votes
1 answer

Why is "use strict" still a string literal?

Why do we still have to use quoted string literal to switch on strict in JS? Surely something a little more strongly 'typed' could be used here, like calling a built in function, say, Object.UseStrict()or something like that. What is the reason…
ProfK
  • 49,207
  • 121
  • 399
  • 775
25
votes
2 answers

"use strict" in javascript

I have been reading many JavaScript codes recently and I was wondering of what are the benefits of using "use strict". Any idea would be very much appreciated.
Tepken Vannkorn
  • 9,648
  • 14
  • 61
  • 86
23
votes
4 answers

Javascript/jsLint: What to replace jQuery(this) with when using "use strict";

When I validate the following code with jslint I get the following errors. function displayMegaDropDown() { "use strict"; var liMegaPosition, divMegaOffset; liMegaPosition = jQuery(this).position(); divMegaOffset = { top: liMegaPosition.top +…
Sarge
  • 2,367
  • 2
  • 23
  • 36
23
votes
2 answers

Does the type of quotes matter when using use strict?

I was wondering since I'm trying to use use strict, does it matter if I go with "use strict" or 'use strict'? Is any of those a «more correct» option?
Zentaurus
  • 758
  • 2
  • 11
  • 27
17
votes
2 answers

Is "use strict" Safe for Live Sites?

"use strict"; seems awesome, and we'd really like to use it at our shop. However, we just want it so that we (the developers) can find strictness-issues; we very much DO NOT want to make our site break for our actual customers when it was working…
machineghost
  • 33,529
  • 30
  • 159
  • 234
12
votes
1 answer

use strict in javascript not working for fat arrow?

I found an interesting case where "use strict" is not working as expected in javascript. Following functions "use strict"; var y = () => { console.log(this); } var x = function () { console.log(this); } x(); // undefined due to use…
gorgi93
  • 2,457
  • 8
  • 30
  • 53
12
votes
2 answers

Why is "use" not allowed, as in "use strict;" in Perl 5.14?

I am trying to use the following conventions I have been instructed to use for good/proper/safe Perl code for my "Hello, World!" Program: use strict; use warnings; I have created and successfully run the following "Hello World" program using…
bc1984adam
  • 173
  • 1
  • 9
1
2 3 4 5 6 7