roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Aditya Sharma (Jira)" <>
Subject [jira] [Created] (ROL-2157) Variables should be declared explicitly in Custom JS code
Date Sun, 03 Nov 2019 07:24:00 GMT
Aditya Sharma created ROL-2157:

             Summary: Variables should be declared explicitly in Custom JS code
                 Key: ROL-2157
             Project: Apache Roller
          Issue Type: Improvement
            Reporter: Aditya Sharma
            Assignee: Aditya Sharma

Pattern is identified and reported at as Blocker

JavaScript variable scope can be particularly difficult to understand and get right. The situation
gets even worse when you consider the _accidental_ creation of global variables, which is
what happens when you declare a variable inside a function or the {{for}} clause of a for-loop
without using the {{let}}, {{const}} or {{var}} keywords.

{{let}} and {{const}} were introduced in ECMAScript 2015, and are now the preferred keywords
for variable declaration. 

Noncompliant Code Example

function f(){
 i = 1; // Noncompliant; i is global
for (j = 0; j < array.length; j++) { // Noncompliant; j is global now too
 // ...

Compliant Solution

function f(){
 var i = 1;
for (let j = 0; j < array.length; j++) {
 // ...

This message was sent by Atlassian Jira

View raw message