Questions tagged [strict]

Mode used in languages such as Javascript and Perl to be able to code with a restricted version of those languages.

490 questions
10
votes
2 answers

'use strict' not stopping hoisting in function scope

My Problem Lies here I'm learning JavaScript But not new to Programming at all. I understand hoisting, but with strict mode shouldn't this produce an error and be caught either when 6 is assigned to undeclared a variable or document.getElement... is…
Zach Hutchins
  • 103
  • 1
  • 4
10
votes
1 answer

Nodejs methods with 'thisArg' and 'use strict'; issue

I have node v0.10.28 installed along with V8 v3.14.5.9 on Fedora 19. The issue I am having is with methods that have a thisArg optional argument, like Array.prototype.forEach. If I execute the following code on Chromium v33 or Firefox v28 -…
Xotic750
  • 22,914
  • 8
  • 57
  • 79
10
votes
1 answer

Haskell: Guidelines for using Strictness

Is there any recommend guidelines when to use strictness in Haskell ? For example, I was looking on the tagsoup library. They have one of their data structure defined like this: data Tag str = TagOpen str [Attribute str] | TagClose str …
Sibi
  • 47,472
  • 16
  • 95
  • 163
9
votes
2 answers

Function executes faster without STRICT modifier?

I stumbled upon a slump in performance when a simple SQL function is declared STRICT while answering this question. For demonstration, I created two variants of a function ordering two elements of an array in ascending order. Test setup Table with…
Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
9
votes
2 answers

What does "use strict" add for TypeScript code?

This question is a copy of “Use Strict” needed in a TypeScript file? There are some answers, but it is not clear for what does "use strict" statement in TypeScript, when tsc shoes me strict mode errors without this statement. But decided to ask as…
Yauhen
  • 1,145
  • 12
  • 19
9
votes
2 answers

JavaScript: define a constant inside try / catch with strict mode

Today I run into a weird JS bug, working with const inside a try/catch block, and I'd like to better understand what is causing it. Let's look at a code example, that is worth more than a thousand words: try { const FOO = 'bar'; …
Pensierinmusica
  • 6,404
  • 9
  • 40
  • 58
9
votes
2 answers

Blank page if I declare(strict_types=1); in PHP 7 at top of the file

Recently I was checking out on PHP 7, specifically return type declaration and type hinting. I have compiled PHP 7 from source(master branch from Github) and running it in Ubuntu 14.04 virtual box. I tried to run following code to get a test of new…
pinkal vansia
  • 10,240
  • 5
  • 49
  • 62
9
votes
1 answer

"use strict"; now allows duplicated properties?

I just found that in the last Chrome 42 and FF 37.0.2 this lines of code are perfectly legal "use strict"; var o = { p: 1, p: 2 }; (copy-pasted from MDN ) In IE 10-11 and Opera 28.0.1750 it throws error as expected. In the same time,…
Andrey Kuleshov
  • 645
  • 6
  • 19
9
votes
2 answers

Is it safe to use 'use strict' in IE 8/9

According the this http://caniuse.com/use-strict 'use strict' does not support in IE version 8/9. My question is, Is it really safe to use 'use strict' in IE 8/9 or browsers that its not compatible with? Will it break my code?
Shabith
  • 3,005
  • 3
  • 23
  • 20
9
votes
3 answers

Ensuring files are closed promptly

I am writing a daemon that reads something from a small file, modifies it, and writes it back to the same file. I need to make sure that each file is closed promptly after reading before I try to write to it. I also need to make sure each file is…
mhwombat
  • 8,026
  • 28
  • 53
8
votes
2 answers

Why doesn't "use strict" (JavaScript) detect an undeclared variable?

I'm trying to get the "use strict"; directive to work, and having a bit of trouble. In the following file FireFox 9 will (correctly) detect that someVar hasn't been declared on line 3, but fails to detect that theVar hasn't been declared on line…
MikeTheTall
  • 3,214
  • 4
  • 31
  • 40
8
votes
2 answers

Is this strict aliasing violation? Can any type pointer alias a char pointer?

I'm still struggling to understand what's allowed and not allowed with strict aliasing. With this concrete example is it violation of strict aliasing rule? If not, why? Is it because I placement new a different type into a char* buffer? template…
Zebrafish
  • 11,682
  • 3
  • 43
  • 119
8
votes
2 answers

Why is this illegal in strict mode?

Yeah, yeah, I know, strict mode ain't around yet, but really, I'm planning for the future... So, why is this: $('#'+ $(this).attr('id').replace('control-', 'legend-')).fadeIn(); ... not allowed in ES5 Strict mode? Or am I misinterpreting?…
Félix Saparelli
  • 8,424
  • 6
  • 52
  • 67
8
votes
1 answer

In Javascript, how can I check if a function is in strict mode *without changing the function*?

I want to write a test suite to ensure some given functions are using strict mode. There are many of them, and manually inspecting them seems like a chore. An answer in a similar question uses a regex on the function's definition to check. However,…
nfirvine
  • 1,479
  • 12
  • 23
8
votes
2 answers

Variable behavior, name-based discrepancy

Symptom: $c="foo"; throws an error and $b="foo"; does not. My script is literally 3 lines. The following produces no errors or warnings: use strict; $b = "foo"; print $b; but if I change to the following, I get a "requires explicit package name"…
mic angelo
  • 115
  • 1
  • 8