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.
use-strict
100
questions
0
votes
1
answer
151
views
JavaScript: duplicate property name and getter/setter an error in ES5?
JS noob here: If a getter/setter with a particular name is used that is the same as a property's name that takes on a value, and in code that is in strict mode, will an error occur in ES5? Ex (where ...
1
vote
2
answers
2k
views
How to disable "Use Strict" in Jest
I am writing some unit tests for a codebase which uses octal literals. Whenever the test is executed with npm test, a syntax error appears as follows:
Legacy octal literals are not allowed in strict ...
1
vote
1
answer
245
views
Use strict is not working when I call my hoisted function
I have the following code
"use strict";
x = 12;
function myFunction() {
}
myFunction();
so i am using use strict at the top of my script and now I am in strict mode - so I can't have ...
1
vote
1
answer
203
views
I have 'use-strict' mode in JS enabled implicitly [closed]
It turns out that I have 'use-strict' enabled and I don't know why...
const isStrict = () => !this
console.log( isStrict() );
This code returns me true and I'm testing it in a plain .js file, ...
1
vote
1
answer
2k
views
"use strict" does not work on ES6 using Visual Studio Code
In "use strict" mode, this in function should be [object Window] rather than the object that calls the function in regular mode. But when I'm trying to proof of concept, it doesn't work, I'm ...
3
votes
2
answers
282
views
`use strict` is not working when we use template literals
If I enclose use strict with backticks/template literals, 'use strict' is not working as expected. Can you share the reason behind it? Are there any similar exceptional statements where template ...
0
votes
1
answer
57
views
Why does this code create the object, but still treats it as undefined? [duplicate]
I don't understand why doesn't this code work as expected:
"use strict";
window.obj.prop = (() => {
window.obj = { myobj: true };
return "value";
})();
I always thought that = operator ...
1
vote
0
answers
44
views
I read that 'use strict' error but it doesn't tell what exactly is causing the error
Seems like there is a bad coding habit but it doesn't tell exactly where. Anybody has an experience with that?
this is the code causing an error
$scope.removeAllSelectedItems = function (...
-1
votes
1
answer
224
views
How to use undeclared variables in Reactjs
I am creating a script node in my react code on run time using document.createElement('script') and assigning its src to a url,
Now I want to use the variable of the included JS in my react code ...
1
vote
1
answer
863
views
Why isn't "use strict" default?
Why isn't "use strict" the default way to interpret ES6 javascript, preferring the functionality: "do not use strict" (or whatever) to turn it off?
Previously, I imagined "use strict" as sort of like ...
1
vote
1
answer
487
views
JavaScript "use strict" inconsistently working in Chrome snippets / DevTools Sources panel
I am currently taking a Udemy course on "Advanced" Javascript concepts (https://www.udemy.com/course/javascript-advanced/), and the first lesson goes over the "use strict" command and its ...
4
votes
1
answer
482
views
How to count the number of arguments to a JavaScript function without using "arguments"?
I've been updating a library I wrote some time ago, and in doing so have realized that there are unexpected errors when testing in strict mode. These arise because of checks at the beginning of some ...
0
votes
0
answers
147
views
Not-enabled 'use strict' is blocking execution of the code
Yesterday, I was practicing just a real basics and everything worked fine. But when I opened test html today, I noticed that there are the error now:
const otherDate = new Date();
document....
2
votes
1
answer
8k
views
How to require jQuery in Node using Gulp?
Building a PWA on top of NodeJS. Utilizing gulp to processes package/bundle for production. Also using jQuery.
Receiving the error:
Uncaught ReferenceError: jQuery is not defined
package.json:
"...
3
votes
1
answer
84
views
With "use strict" enabled, why can I assign a variable without let while using prompt()
I wrote "use strict"; at the top of my script.
I can't write num = 5; because I get ReferenceError: Can't find variable: num.
To fix this I can write let num = 5;.
Using that logic, why am I ...
2
votes
1
answer
2k
views
Does "use strict" still work the same way in ES6?
I read an answer that "use strict" helps in restricting access to global variables and throwing unnecessary exceptions. But I just happened to wonder, whether "use strict" is still popular in ES6? OR ...
0
votes
2
answers
87
views
WebStorm on Ubuntu issue
A few days ago I installed Ubuntu on my computer and then WebStorm but I'm having an issue with JavaScript projects. It gave me an error saying that I cannot use the word "let". After a few hours, I ...
5
votes
2
answers
1k
views
"use strict" in the middle of the program
Why the second function didn't use the "use strict"; mode (it shows me window object in console):
function test() {
console.log(this);
}
test(); // will be global or window, it's okay
"use ...
1
vote
1
answer
2k
views
Angular: "use strict" IE11
I ran into a problem in the browser IE11. The project is in Angular 2/4.
Error: Multiple definitions of a property not allowed in strict mode.
In file main.bundle.js
0
votes
1
answer
580
views
Meteor won't start. "Block-scoped declarations (let, const, function, class) not yet supported outside strict mode" in ejson.js
I'm new to Meteor, and only trying to install and get a new app running. I had things were working last Friday, but had to reinstall today and can no longer get the app running.
The install has been ...
0
votes
0
answers
333
views
"use strict" issue in Edge browser from angular 4
I am having trouble to resolve this issue which appears in Edge browser. Have tried manually removing "use strict" from my build, which did not help me out.
I am using the latest angular 4.3.6 in my ...
1
vote
1
answer
67
views
Javascript - Assign (not clone) a large object to a new variable to reduce its name
I want to assign a large object to a new variable to reduce its name, but I have an error : "realEstateProjectFundReuse" is read-only
const realEstateProjectFundReuse = this.project....
0
votes
1
answer
109
views
Use strict mode on Progress bar
Progress bar is working If I put it directly in the index.html page. But it isn't working (animation) if I put it in external active.js file with "use strict" mode. But Other JS is working fine. ...
0
votes
1
answer
857
views
use strict leads to undefined function
I am trying to organize my js file and followed a suggested module pattern. When I use "use-strict" in this pattern a function is declared as undefined, without the "use-strict" method the function ...
2
votes
2
answers
1k
views
"use strict" and naming arguments in function calls
A colleague advised me to add "use strict"; to the top of my JS code to highlight any gaps in my definitions and potential reference errors, etc. I am very happy with it because it has identified ...
0
votes
0
answers
611
views
Why "use strict"; prevent a jQuery click event on Safari?
My jQuery click event does not work when I use the "strict mode" in my external javascript file. The "use strict"; is placed on top of the file.
However, the click event does works when using the ...
2
votes
2
answers
452
views
How to disbale 'use strict' for jshint in Atom
I would like to disable JSHint warning "W097": use function form of 'use strict'.
I know I can place /* jshint -W097 */ and /* jshint node: true */
But I don't want to manually add that on top of ...
5
votes
1
answer
13k
views
Assignment to read-only properties is not allowed in strict mode IE11
I have been told by IE11 that var self = this is a read-only variable... Yet I am not assigning anything to it after its declaration point. The only variable is height that is changing. Even though, i ...
1
vote
1
answer
1k
views
Is it necessary to use strict when using certain es6 methods in Node.js [duplicate]
We are having a debate at my work, some people say when using es6 and nodejs, without babel of course, you should always add 'use strict' BECAUSE some es6 methods may not work. I can't find ...
0
votes
0
answers
65
views
What happens if I don't put "use strict" in a function? [duplicate]
What's the difference following two cases?
Using use strict at the top of the file, not in a function
"use strict";
(function () {
// ...
})();
Using use strict in the wrapping function
(...
3
votes
2
answers
68
views
Why does strict mode make such simple actions such different?
There is an extremely simple algorythm, which works surprisely different in two cases, depending on the presence of "use strict".
Case 1:
If func() declaration is within the strict mode, than ...
0
votes
2
answers
3k
views
'use-strict' enabled but not working in node
I have enabled use-strict mode in my .js file but when I run it, node keeps telling me that I don't have it enabled. PLEASE don't tell me to write "use-strict"; at the top of my file because I already ...
3
votes
0
answers
224
views
"Use Strict" and the applicable scope [duplicate]
I am interested to learn when using strict mode, where does it apply to. I know that I cannot put it once in my file and be done, rather it has to be in the functions, etc. I was told if I put it in ...
12
votes
1
answer
2k
views
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 () {
...
1
vote
1
answer
78
views
Using "using strict" as a backup for "use strong"
Is there someway to use "use strong"; and have "use strict"; used as a backup? Since it appears like Google Chrome is the only browser to support "use strong"; at the moment.
7
votes
1
answer
1k
views
JS: What is 'this' coercion? What does use-strict have to do with that?
I read the following on a website:
Use-strict has an advantage. It eliminates this coercion. Without
strict mode, a reference to a this value of null or undefined is
automatically coerced to ...
1
vote
3
answers
284
views
Why is typescript complaining when a /// reference is after 'use strict'?
This question is some what related to Why is typescript failing to import a module?, which I asked yesterday. The initial setup is the same.
I have a simple typescript file like this:
/// <...
9
votes
2
answers
2k
views
How to set 'use strict' globally with JSLint
I'm new to javascript and am trying to validate through JSLint.
Where should I put "use strict" to use it globally and validate?
This gives me error "Unexpected expression 'use strict' in statement ...
2
votes
2
answers
315
views
custom 'use strict' like directives
I'm looking for a better logging/debugging method for my project. So I came up with the idea to use custom directives like the 'use strict'.
Is it possible to write something like this
function xyz (...
1
vote
0
answers
45
views
make class such that configure one time & use method of that class in any file in project
All i want is to make 1 time configuration in main file(main.js) while server starts... And use method of that class multiple time in different files(conn1.js,conn2.js)...
i am making a npm module ...
52
votes
16
answers
61k
views
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 ...
2
votes
1
answer
1k
views
How can I fix "Missing 'use strict' statement"?
$(document).ready(function(){
'use strict';
$('#c2').hide('slow');
});
<html>
<body>
<div class="container">
<div class="Header">
<nav>
...
3
votes
3
answers
2k
views
Variable typeof object in strict mode?
This piece of JavaScript ran fine without "use strict";. But how can I check if a global variable exists with strict mode and what type it has without running into a undeclared variable error?
if (!(...
3
votes
2
answers
269
views
"use strict" inheritance / scope
//Global Scope
"use strict"; //1
function A() {
"use strict"; //2
function innerA() {
"use strict"; //3
}
}
I was just wondering:
Is doing use strict at //1 is enough or do we ...
1
vote
1
answer
1k
views
Why is 'Use Strict' causing functions to be undefined
I have a partial that is loading two scripts. The second script calls a function in the first script... Both scripts use "use strict;" at the top. When the second script calls the function in the ...
59
votes
6
answers
51k
views
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 ...
1
vote
1
answer
1k
views
Do I need to use the function form of 'use strict' in jasmine test files?
I'm building unit tests in jasmine based on examples I've seen with AngularJS. The examples, such as this unit test in the Angular PhoneCat tutorial, use the global form of 'use strict'. However, ...
1
vote
4
answers
5k
views
How to get rid of use-strict warning when using webpack and jshint-loader?
I have a webpack project wired with the jshint-loader which is defined like so:
postLoaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'jshint-loader'...
1
vote
0
answers
768
views
JSHint Function Is Not Defined
I am trying to write better Javascript / JQuery code and I set up JSHint with my Grunt.
Now I have gone though my code and its seems to be ok, without using 'strict'. I have split my code into many ...
8
votes
0
answers
121
views
Does "use strict" offer any speed improvements? [duplicate]
Leaving aside possible differences stemming from code structure changes to conform with "use strict";, does running code in strict mode offer any speed benefits?