@jgCarroll/

useStrict

JavaScript

A common interview question

fork
loading
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
'use strict'

city = 'London'

console.log(city) // throws an error because city is not declared as a variable. Without 'use strict' this would log 'London'

// =================================

// this (below) will also throw an error because all parameters must be unique

function myFunc(a, a, b) {
  console.log(a, a, b)
}

myFunc(1, 2, 3)

// ============================

// This example (below) won't work with or without strict mode, but with strict mode it throws an error.

'use strict';
 
delete Object.prototype;
Native Browser JavaScript