All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.javascript.rules.javascript.FunctionDeclarationsWithinBlocks.html Maven / Gradle / Ivy

There is a newer version: 2.5
Show newest version

While most script engines support function declarations within blocks, it is not part of ECMAScript 5 and below, and from browser to browser the implementations are inconsistent with each other. ECMAScript 5 and below only allows function declarations in the root statement list of a script or function. If you are targeting browsers that don't support ECMAScript 6, use a variable initialized with a function expression to define a function within a block :

Noncompliant Code Example

if (x) {
  function foo() {}
}

Compliant Solution

if (x) {
  var foo = function() {}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy