“Modo estricto” Código de respuesta

JavaScript Modo estricto en función

myVariable = 9;
console.log(myVariable); // 9

function hello() {

    // applicable only for this function
    'use strict';

    string = 'hello'; // throws an error
}

hello();
SAMER SAEID

Modo estricto

Strict mode makes several changes to normal JavaScript semantics:
-Eliminates some JavaScript silent errors by changing them to throw errors.
-Fixes mistakes that make it difficult for JavaScript engines to perform 
optimizations: strict mode code can sometimes be made to run faster than 
identical code that's not strict mode.
-Prohibits some syntax likely to be defined in future versions of ECMAScript.
Owlthegentleman

Encienda Modern JS agregando Use Strict a su script

// Non-strict code...

(function(){
  "use strict";

  // Define your library strictly...
})();

// Non-strict code... 
Aggressive Ant

Use JavaScript estricto

// File: myscript.js

'use strict';
var a = 2;
....
Repulsive Raven

Use JavaScript estricto

function doSomething() {
    'use strict';
    ...
}
Repulsive Raven

Respuestas similares a “Modo estricto”

Preguntas similares a “Modo estricto”

Más respuestas relacionadas con “Modo estricto” en JavaScript

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código