123

This error pops up on my JS console in the browser, and I'm not sure how to interpret the message. Can anyone describe what causes this?

Thanks

rogerrw
  • 1,864
  • 3
  • 15
  • 18

1 Answers1

135

This means that you must declare strict mode by writing "use strict" at the beginning of the file or the function to use block-scope declarations.

EX:

function test(){
    "use strict";
    let a = 1;
} 
brainjam
  • 18,863
  • 8
  • 57
  • 82
Omar Elawady
  • 3,300
  • 1
  • 13
  • 17
  • 19
    I've got the same problem, added "use strict" at the top of my function but still doesn't works... Any idea? Thanks – ZAD Dec 15 '15 at 09:21
  • 6
    This might be node.js app. – Teoman shipahi Jan 14 '16 at 13:58
  • 1
    @FarzadCyrus it doesn't work for me either - I'm using the chrome console 48.0.2564.103 m – kayakpim Feb 08 '16 at 14:50
  • 1
    @FarzadCyrus got it working using (function() { "use strict"; })(); in the console – kayakpim Feb 08 '16 at 14:59
  • @kayakpim Yes mate, for some reason it wasn't working initially, but after restarting my browser it worked fine! Not sure what was it causing the browser to behave like that... but surely wasn't to do with the script itself! It sometimes happens to the JS engines... hope it helps... Have you tried it on jsFiddle or CodePen? Cheers – ZAD Feb 10 '16 at 09:32
  • 2
    I'm getting this in a node app, how to fix? – SuperUberDuper Jun 20 '16 at 10:15
  • 13
    For node it's node --use_strict – homemade-jam Oct 12 '16 at 23:50
  • 12
    I'm using node v7.2.0 and use strict isn't needed for let anymore – granmoe Dec 09 '16 at 20:08
  • My problem was with cordova. I updated with 'n' to the latest version of node, now it works fine. http://stackoverflow.com/a/19584407/530197 – insign Feb 01 '17 at 20:37
  • What you say doesn't work. I have `"use strict"` everywhere in my files and still have the issue – Green Feb 24 '17 at 05:47
  • I got the same issue for my node js app (express). I used "use strict" at beginning and problem solved. – Avijit Majhi Jun 26 '17 at 12:36
  • i tried this with use strict, but i got many errors, instead i removed let and used var instead that solved my issue – rashidnk Jul 11 '17 at 11:30
  • Too me worked only adding the `;` at the end, which means `"use strict";` – insign Jul 19 '17 at 17:45