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
3
votes
3 answers

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 (!(typeof a === 'object')) { a = ... /* complex…
powtac
  • 40,542
  • 28
  • 115
  • 170
3
votes
2 answers

"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 have to be explicit at all places like //2 and…
dopeddude
  • 4,943
  • 3
  • 33
  • 41
3
votes
1 answer

Is there a systematic way to check for `strict refs`?

We've adopted use strict in our legacy Perl codebase over the last few years. I've been tasked with adding it to the remaining modules, while ensuring of course that it doesn't break anything. Now for use strict 'vars' and use strict 'subs' this is…
Stefan Majewsky
  • 5,427
  • 2
  • 28
  • 51
3
votes
4 answers

JSLint Strict Violation. Object Oriented Javascript frustrations

I'm trying to learn to do object oriented programming in JavaScript and getting JSLint strict violations. I understand that I'm using this in a non-global context (or something to that effect...), but I don't know how to do it properly. Here's my…
Captain Stack
  • 3,572
  • 5
  • 31
  • 56
3
votes
3 answers

In Perl, how to share a variable between subroutines, with use strict?

If I don't use strict; the following code works fine and prints out "alice": assign_name(); print_name(); sub assign_name { $name = "alice"; } sub print_name { print $name; } However when I do use strict; then I know I'll have to declare…
WSBT
  • 33,033
  • 18
  • 128
  • 133
2
votes
1 answer

JSON.parse without Strict Mode

I'm reading the John Resig blog about the Strict Mode in javascript, but i have a question. One of the features of Strict Mode, is the use of JSON.parse and JSON.stringify, but i can use it WITHOUT "use strict". If you write the same example that…
Otuyh
  • 2,384
  • 5
  • 22
  • 40
2
votes
2 answers

`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 literals are not going to work as expected? `use…
2
votes
1 answer

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: "devDependencies": { "browserify": "^16.2.2", …
Clay Hess
  • 228
  • 6
  • 24
2
votes
1 answer

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 is there an alternate (better) way today to…
2
votes
2 answers

"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 several pieces of code which might have been a…
Jack Parkinson
  • 681
  • 11
  • 35
2
votes
2 answers

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 every page. Is there a way to disable from the source…
Fernando B
  • 864
  • 2
  • 12
  • 27
2
votes
2 answers

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 () { 'loglevel: info'; /// Some other code …
harmoniemand
  • 249
  • 4
  • 14
2
votes
1 answer

How can I fix "Missing 'use strict' statement"?

$(document).ready(function(){ 'use strict'; $('#c2').hide('slow'); });
2
votes
1 answer

Why "let" es6 harmony works only with use strict?

This code: var x = 8, y = 12; let ( x = 5, y = 10) { return x + y; } ..gives "SyntaxError: Illegal let declaration outside extended mode" But with "use strict" it works fine. So it's interesting why 'let' first integrated with "use strict"…
ButuzGOL
  • 1,233
  • 2
  • 13
  • 27
2
votes
0 answers

Does adding "use strict"; to a function block affect methods and properties added later on to the prototype?

Did a few searches for this and didn't find anything exact. Please consider the following example: function ConstructIt (param) { "use strict"; // Set up the object } My question pertains to each of the following scenarios: Scenario 1: In…