SlideShare a Scribd company logo
1 of 28
Download to read offline
“use me strict”;
Table of contents
1. What is strict mode?
2. What does strict mode do?
3. How and can I use strict mode?
4. What does strict mode change?
5. What should you be aware using strict mode?
6. So should I use it on production?
1. What is strict mode?
?
ECMA International
ECMAScript language standard
ECMA 262 standard
Strict Mode is a feature in ECMAScript 5 that
allows you to place a program, or a function,
in a "strict" operating context.
This strict context prevents:
- certain actions from being taken
- throws more exceptions.
2. What does strict mode do?
Strict mode helps out
in a couple ways:
It catches some common coding bloopers,
throwing exceptions.
It prevents, or throws errors, when relatively
"unsafe" actions are taken.
It disables features that are confusing or
poorly thought out.
3. How to use strict mode?
put it at the top of document
or function before other statements:
"use strict"; or 'use strict';
"use strict";
var message = "I'm a strict mode";
4.1 converting mistakes into errors
4.2 simplifying variable uses
4.3 making eval and arguments simpler
4.4 "securing" JavaScript
4.5 prepare for the future
4 What does strict mode change?
4.1.1 global variables
4.1.2 NaN assigment
4.1.3 assignment to a non-writable property
4.1.4 assignment to a getter-only property
4.1.5 assignment to a new property on a non-extensible object
4.1.6 delete undeletable properties - native code
4.1.7 all properties named in an object literal be unique
4.1.8 strict mode requires that function argument names be unique
4.1.9 octal numbers serve errors
4.1 Converting mistakes into errors
!
4.1.1 misspelled variables
"use strict";
zmiennna = 10;
// Uncaught ReferenceError: zmiennna is not defined
//non strict
zmiennna = 10; // window.zmiennna is set
4.1.2 NaN assigment
"use strict";
NaN = 1;
// Uncaught TypeError:
// Cannot assign to read only property 'NaN' of [object Object]
//non strict
NaN = 1; // no reaction
4.1 Converting mistakes into errors...
4.1.3 assignment to a non-writable property
"use strict";
var obj1 = {};
Object.defineProperty(obj1, "x", { value: 1, writable: false });
obj1.x = 10;
// Uncaught TypeError: Cannot assign to read only property 'x' of #<Object>
//non strict
obj1.x = 10; // no reaction - obj1.x is still equal to 1
4.1.4 assignment to a getter-only property
"use strict";
var obj2 = { get x() { return 2; } };
obj2.x = 5;
// Uncaught TypeError:
// Cannot set property x of #<Object> which has only a getter
//non strict
obj1.x = 10; // no reaction
4.1 Converting mistakes into errors...
4.1.5 assignment to a new property on a non-extensible object
"use strict";
var fixed = {};
Object.preventExtensions(fixed);
fixed.newProp = “new thing”;
// Uncaught TypeError: Can't add property newProp, object is not extensible
//non strict
fixed.newProp = “new thing”; // no reaction
4.1.6 delete undeletable properties from native code
"use strict";
delete Object.prototype;
// Uncaught TypeError:
// Cannot delete property 'prototype' of function Object() { [native code]
//non strict
delete Object.prototype; // no reaction
4.1 Converting mistakes into errors...
4.1.7 all properties named in an object literal be unique
"use strict";
var o = { p: 1, p: 2 };
// Uncaught SyntaxError:
// Duplicate data property in object literal not allowed in strict mode
//non strict
o.p === 2 //overwritten value
4.1.8 function argument names be unique
"use strict";
function sum(a, a, c){
return a + b + c;
}
// Uncaught SyntaxError:
// Strict mode function may not have duplicate parameter names
//non strict - error after calling function
sum(2,3,4); // Uncaught ReferenceError: b is not defined
4.1 Converting mistakes into errors...
4.1.9 octal numbers serve errors
//Actually, this effort of getting rid of octal literals comes since 1999.
parseInt("010"); // 10, ECMAScript 5 behavior
parseInt("010"); // 8, ECMAScript 3 behavior
"use strict";
var sum = 011 + 120;
// Uncaught SyntaxError: Octal literals are not allowed in strict mode.
//non strict
var sum = 011 + 120; //sum === 129
4.1 Converting mistakes into errors...
4.2.1 prohibits with
4.2.2 eval sets variable which not overwrite other variables
4.2.3 forbids deleting plain names
4.2 Simplifying variable uses
!
4.2.1 prohibits with
"use strict";
var x = 17;
with (obj) {
x = 10;
}
// Uncaught SyntaxError: Strict mode code may not include a with statement
//non strict
// if obj.x does not exist global x will be overwritten
4.2 Simplifying variable uses...
4.2.2 eval sets variable which not overwrite other variable
"use strict";
var x = 17;
var evalX = eval("'use strict'; var x = 42; x");
// x === 17 && evalX === 42
//non strict
// x != 17 && evalX === 42
4.2.3 forbids deleting plain names
"use strict";
eval("var x; delete x;");
//Uncaught SyntaxError: Delete of an unqualified identifier in strict mode.
//non strict deletes x
4.2 Simplifying variable uses...
4.3.1 the names eval and arguments can't be bound or assigned
in language syntax.
4.3.2 doesn't alias properties of arguments objects created within it
4.3.3 arguments.callee is no longer supported
4.3 Making eval and arguments simpler
!
4.3.1 the names eval and arguments can't be bound or assigned
in language syntax.
"use strict";
eval = 17;
arguments++;
++eval;
var obj = { set p(arguments) { } };
var eval;
try { } catch (arguments) { }
function x(eval) { }
function arguments() { }
var y = function eval() { };
var f = new Function("arguments", "'use strict'; return 17;");
// Uncaught SyntaxError:
// Assignment to eval or arguments is not allowed in strict mode
4.3 Making eval and arguments simpler...
4.3.2 doesn't alias properties of arguments objects created within it
(function (a, b) {
"use strict";
arguments[0] = arguments[1];
console.log(a, b);
}('one', 'two')); // one two
//non strict
(function (a, b) {
arguments[0] = arguments[1];
console.log(a, b);
}('one', 'two')); // two two
4.3.3 arguments.callee is no longer supported
// Uncaught TypeError: 'caller', 'callee', and 'arguments' properties
// may not be accessed on strict mode functions
// or the arguments objects for calls to them
// solution -> name your functions
4.3 Making eval and arguments simpler...
4.4.1 this is undefined - global objects
4.4.2 invoking caller and arguments in function
4.4.3 arguments for functions no longer provide access
to the corresponding function call's variables
4.4.4 function declared inside a statement or a block cause errors
4.4 “Securing” JavaScript
!
4.4.1 this is undefined - global objects
"use strict";
function fun() { return this; }
fun(); //undefined
//non strict
function fun() { return this; }
fun(); //window
4.4 “Securing” JavaScript...
4.4.2 invoking caller and arguments in function
function restricted(){
"use strict";
restricted.caller;
restricted.arguments;
}
function privilegedInvoker() {
return restricted();
}
privilegedInvoker();
// Uncaught TypeError: 'caller', 'callee', and 'arguments' properties
// may not be accessed on strict mode functions
// or the arguments objects for calls to them
//non strinct
// we get function which was calling our function and arguments - not secure
4.4 “Securing” JavaScript...
4.4.3 arguments for functions no longer provide access
to the corresponding function call's variables
function fun(a, b) {
“use strict";
var v = 12;
return arguments.caller;
}
// Uncaught TypeError: 'caller', 'callee', and 'arguments' properties
// may not be accessed on strict mode functions
// or the arguments objects for calls to them
4.4 “Securing” JavaScript...
4.4.4 function declared inside a statement or a block cause errors
"use strict";
if (true){
function f() { }
f();
}
for (var i = 0; i < 5; i++){
function f2() { }
f2();
}
// Uncaught SyntaxError:
// In strict mode code, functions can only be declared at top level
// or immediately within another function.
function baz(){
function eit() { }
}
4.4 “Securing” JavaScript...
You cannot use this words in other way
than they will be implemented:
implements,
interface,
let,
package,
private,
protected,
public,
static,
yield.
4.5 Prepare for the future
- mixing non strict with strict
(Amazon failed with that - offers were not displayed correctly)
- don’t rely on strict mode without testing
5. What should you be aware using strict mode?
Yes and No
6. So should I use it on production ?
6. So should I use it on production...
THANKSHAVE A NICE THURSDAY

More Related Content

What's hot

What's hot (20)

Exception handling & logging in Java - Best Practices (Updated)
Exception handling & logging in Java - Best Practices (Updated)Exception handling & logging in Java - Best Practices (Updated)
Exception handling & logging in Java - Best Practices (Updated)
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Exception Handling in the C++ Constructor
Exception Handling in the C++ ConstructorException Handling in the C++ Constructor
Exception Handling in the C++ Constructor
 
Handling Exceptions In C &amp; C++[Part A]
Handling Exceptions In C &amp; C++[Part A]Handling Exceptions In C &amp; C++[Part A]
Handling Exceptions In C &amp; C++[Part A]
 
Exception handling
Exception handlingException handling
Exception handling
 
130410107010 exception handling
130410107010 exception handling130410107010 exception handling
130410107010 exception handling
 
The definitive guide to java agents
The definitive guide to java agentsThe definitive guide to java agents
The definitive guide to java agents
 
Exception Handling in JAVA
Exception Handling in JAVAException Handling in JAVA
Exception Handling in JAVA
 
Exception handling
Exception handlingException handling
Exception handling
 
Error and exception in python
Error and exception in pythonError and exception in python
Error and exception in python
 
Exceptions handling in java
Exceptions handling in javaExceptions handling in java
Exceptions handling in java
 
Rhino Mocks
Rhino MocksRhino Mocks
Rhino Mocks
 
Exception
ExceptionException
Exception
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
 
Designing Better API
Designing Better APIDesigning Better API
Designing Better API
 
Introduction to Functional Programming (w/ JS)
Introduction to Functional Programming (w/ JS)Introduction to Functional Programming (w/ JS)
Introduction to Functional Programming (w/ JS)
 
Exception handling
Exception handlingException handling
Exception handling
 
Spring AOP
Spring AOPSpring AOP
Spring AOP
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
exception handling in cpp
exception handling in cppexception handling in cpp
exception handling in cpp
 

Similar to Use me strict

Javascript fundamentals and not
Javascript fundamentals and notJavascript fundamentals and not
Javascript fundamentals and not
Salvatore Fazio
 
JavaScript Proven Practises
JavaScript Proven PractisesJavaScript Proven Practises
JavaScript Proven Practises
Robert MacLean
 
Exercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera CymbronExercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera Cymbron
cymbron
 

Similar to Use me strict (20)

1669958779195.pdf
1669958779195.pdf1669958779195.pdf
1669958779195.pdf
 
Enterprise js pratices
Enterprise js praticesEnterprise js pratices
Enterprise js pratices
 
6976.ppt
6976.ppt6976.ppt
6976.ppt
 
JavaScript Cheatsheets with easy way .pdf
JavaScript Cheatsheets with easy way .pdfJavaScript Cheatsheets with easy way .pdf
JavaScript Cheatsheets with easy way .pdf
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
 
Practical JavaScript Programming - Session 7/8
Practical JavaScript Programming - Session 7/8Practical JavaScript Programming - Session 7/8
Practical JavaScript Programming - Session 7/8
 
20150519 qumram barcelona_js
20150519 qumram barcelona_js20150519 qumram barcelona_js
20150519 qumram barcelona_js
 
Javascript tid-bits
Javascript tid-bitsJavascript tid-bits
Javascript tid-bits
 
Say It With Javascript
Say It With JavascriptSay It With Javascript
Say It With Javascript
 
JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.
JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.
JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.
 
OSCON - ES6 metaprogramming unleashed
OSCON -  ES6 metaprogramming unleashedOSCON -  ES6 metaprogramming unleashed
OSCON - ES6 metaprogramming unleashed
 
Javascript fundamentals and not
Javascript fundamentals and notJavascript fundamentals and not
Javascript fundamentals and not
 
JavaScript Proven Practises
JavaScript Proven PractisesJavaScript Proven Practises
JavaScript Proven Practises
 
Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)
 
ES6 metaprogramming unleashed
ES6 metaprogramming unleashedES6 metaprogramming unleashed
ES6 metaprogramming unleashed
 
Perl_Part5
Perl_Part5Perl_Part5
Perl_Part5
 
Java For Automation
Java   For AutomationJava   For Automation
Java For Automation
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testing
 
Java script for web developer
Java script for web developerJava script for web developer
Java script for web developer
 
Exercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera CymbronExercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera Cymbron
 

Recently uploaded

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Krashi Coaching
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Recently uploaded (20)

Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 

Use me strict

  • 2. Table of contents 1. What is strict mode? 2. What does strict mode do? 3. How and can I use strict mode? 4. What does strict mode change? 5. What should you be aware using strict mode? 6. So should I use it on production?
  • 3. 1. What is strict mode? ? ECMA International ECMAScript language standard ECMA 262 standard Strict Mode is a feature in ECMAScript 5 that allows you to place a program, or a function, in a "strict" operating context. This strict context prevents: - certain actions from being taken - throws more exceptions.
  • 4. 2. What does strict mode do? Strict mode helps out in a couple ways: It catches some common coding bloopers, throwing exceptions. It prevents, or throws errors, when relatively "unsafe" actions are taken. It disables features that are confusing or poorly thought out.
  • 5. 3. How to use strict mode? put it at the top of document or function before other statements: "use strict"; or 'use strict'; "use strict"; var message = "I'm a strict mode";
  • 6. 4.1 converting mistakes into errors 4.2 simplifying variable uses 4.3 making eval and arguments simpler 4.4 "securing" JavaScript 4.5 prepare for the future 4 What does strict mode change?
  • 7. 4.1.1 global variables 4.1.2 NaN assigment 4.1.3 assignment to a non-writable property 4.1.4 assignment to a getter-only property 4.1.5 assignment to a new property on a non-extensible object 4.1.6 delete undeletable properties - native code 4.1.7 all properties named in an object literal be unique 4.1.8 strict mode requires that function argument names be unique 4.1.9 octal numbers serve errors 4.1 Converting mistakes into errors !
  • 8. 4.1.1 misspelled variables "use strict"; zmiennna = 10; // Uncaught ReferenceError: zmiennna is not defined //non strict zmiennna = 10; // window.zmiennna is set 4.1.2 NaN assigment "use strict"; NaN = 1; // Uncaught TypeError: // Cannot assign to read only property 'NaN' of [object Object] //non strict NaN = 1; // no reaction 4.1 Converting mistakes into errors...
  • 9. 4.1.3 assignment to a non-writable property "use strict"; var obj1 = {}; Object.defineProperty(obj1, "x", { value: 1, writable: false }); obj1.x = 10; // Uncaught TypeError: Cannot assign to read only property 'x' of #<Object> //non strict obj1.x = 10; // no reaction - obj1.x is still equal to 1 4.1.4 assignment to a getter-only property "use strict"; var obj2 = { get x() { return 2; } }; obj2.x = 5; // Uncaught TypeError: // Cannot set property x of #<Object> which has only a getter //non strict obj1.x = 10; // no reaction 4.1 Converting mistakes into errors...
  • 10. 4.1.5 assignment to a new property on a non-extensible object "use strict"; var fixed = {}; Object.preventExtensions(fixed); fixed.newProp = “new thing”; // Uncaught TypeError: Can't add property newProp, object is not extensible //non strict fixed.newProp = “new thing”; // no reaction 4.1.6 delete undeletable properties from native code "use strict"; delete Object.prototype; // Uncaught TypeError: // Cannot delete property 'prototype' of function Object() { [native code] //non strict delete Object.prototype; // no reaction 4.1 Converting mistakes into errors...
  • 11. 4.1.7 all properties named in an object literal be unique "use strict"; var o = { p: 1, p: 2 }; // Uncaught SyntaxError: // Duplicate data property in object literal not allowed in strict mode //non strict o.p === 2 //overwritten value 4.1.8 function argument names be unique "use strict"; function sum(a, a, c){ return a + b + c; } // Uncaught SyntaxError: // Strict mode function may not have duplicate parameter names //non strict - error after calling function sum(2,3,4); // Uncaught ReferenceError: b is not defined 4.1 Converting mistakes into errors...
  • 12. 4.1.9 octal numbers serve errors //Actually, this effort of getting rid of octal literals comes since 1999. parseInt("010"); // 10, ECMAScript 5 behavior parseInt("010"); // 8, ECMAScript 3 behavior "use strict"; var sum = 011 + 120; // Uncaught SyntaxError: Octal literals are not allowed in strict mode. //non strict var sum = 011 + 120; //sum === 129 4.1 Converting mistakes into errors...
  • 13. 4.2.1 prohibits with 4.2.2 eval sets variable which not overwrite other variables 4.2.3 forbids deleting plain names 4.2 Simplifying variable uses !
  • 14. 4.2.1 prohibits with "use strict"; var x = 17; with (obj) { x = 10; } // Uncaught SyntaxError: Strict mode code may not include a with statement //non strict // if obj.x does not exist global x will be overwritten 4.2 Simplifying variable uses...
  • 15. 4.2.2 eval sets variable which not overwrite other variable "use strict"; var x = 17; var evalX = eval("'use strict'; var x = 42; x"); // x === 17 && evalX === 42 //non strict // x != 17 && evalX === 42 4.2.3 forbids deleting plain names "use strict"; eval("var x; delete x;"); //Uncaught SyntaxError: Delete of an unqualified identifier in strict mode. //non strict deletes x 4.2 Simplifying variable uses...
  • 16. 4.3.1 the names eval and arguments can't be bound or assigned in language syntax. 4.3.2 doesn't alias properties of arguments objects created within it 4.3.3 arguments.callee is no longer supported 4.3 Making eval and arguments simpler !
  • 17. 4.3.1 the names eval and arguments can't be bound or assigned in language syntax. "use strict"; eval = 17; arguments++; ++eval; var obj = { set p(arguments) { } }; var eval; try { } catch (arguments) { } function x(eval) { } function arguments() { } var y = function eval() { }; var f = new Function("arguments", "'use strict'; return 17;"); // Uncaught SyntaxError: // Assignment to eval or arguments is not allowed in strict mode 4.3 Making eval and arguments simpler...
  • 18. 4.3.2 doesn't alias properties of arguments objects created within it (function (a, b) { "use strict"; arguments[0] = arguments[1]; console.log(a, b); }('one', 'two')); // one two //non strict (function (a, b) { arguments[0] = arguments[1]; console.log(a, b); }('one', 'two')); // two two 4.3.3 arguments.callee is no longer supported // Uncaught TypeError: 'caller', 'callee', and 'arguments' properties // may not be accessed on strict mode functions // or the arguments objects for calls to them // solution -> name your functions 4.3 Making eval and arguments simpler...
  • 19. 4.4.1 this is undefined - global objects 4.4.2 invoking caller and arguments in function 4.4.3 arguments for functions no longer provide access to the corresponding function call's variables 4.4.4 function declared inside a statement or a block cause errors 4.4 “Securing” JavaScript !
  • 20. 4.4.1 this is undefined - global objects "use strict"; function fun() { return this; } fun(); //undefined //non strict function fun() { return this; } fun(); //window 4.4 “Securing” JavaScript...
  • 21. 4.4.2 invoking caller and arguments in function function restricted(){ "use strict"; restricted.caller; restricted.arguments; } function privilegedInvoker() { return restricted(); } privilegedInvoker(); // Uncaught TypeError: 'caller', 'callee', and 'arguments' properties // may not be accessed on strict mode functions // or the arguments objects for calls to them //non strinct // we get function which was calling our function and arguments - not secure 4.4 “Securing” JavaScript...
  • 22. 4.4.3 arguments for functions no longer provide access to the corresponding function call's variables function fun(a, b) { “use strict"; var v = 12; return arguments.caller; } // Uncaught TypeError: 'caller', 'callee', and 'arguments' properties // may not be accessed on strict mode functions // or the arguments objects for calls to them 4.4 “Securing” JavaScript...
  • 23. 4.4.4 function declared inside a statement or a block cause errors "use strict"; if (true){ function f() { } f(); } for (var i = 0; i < 5; i++){ function f2() { } f2(); } // Uncaught SyntaxError: // In strict mode code, functions can only be declared at top level // or immediately within another function. function baz(){ function eit() { } } 4.4 “Securing” JavaScript...
  • 24. You cannot use this words in other way than they will be implemented: implements, interface, let, package, private, protected, public, static, yield. 4.5 Prepare for the future
  • 25. - mixing non strict with strict (Amazon failed with that - offers were not displayed correctly) - don’t rely on strict mode without testing 5. What should you be aware using strict mode?
  • 26. Yes and No 6. So should I use it on production ?
  • 27. 6. So should I use it on production...
  • 28. THANKSHAVE A NICE THURSDAY