Skip to content

Javascript Coding Style

Benjamin Délèze edited this page Apr 6, 2021 · 10 revisions

#CS400 → #CS499 Javascript

#CS400 Use the w3school JS convention

Use the w3school JS convention where not specified otherwise by our coding style.

#CS401 Use 2 spaces indentation

To be consistent with our C/C++ coding style, we must use 2 spaces (instead of 4) to indent code.

#CS402 Don't use unneeded curly brackets

To be consistent with our C/C++ coding style, don't use curly brackets when not needed (e.g., for single instruction blocks).

#CS403 Check for undefined variable

Use the following syntax to check for an undefined variable:

typeof data === 'undefined'

#CS404 Use ES6 features

Use ES6 features in the code. For example:

  • OOP-style class instead of prototypes
  • arrow functions
  • constants
  • blocked scoped variables

#CS405 Use ESLint linter (atom package: linter-eslint)

All the errors reported by ESLint based on the https://github.com/cyberbotics/webots/blob/master/.eslintrc.json configuration file should be fixed. Warnings may be accepted.

Clone this wiki locally