Opera Software Javascript Styleguide
In general, we are using the Google JavaScript Styleguide, but on top of that we have defined some rules that clarify things not stated there.
As working on JavaScript involved a great deal of working with HTML and CSS, please also check out the Google HTML/CSS Styleguide and follow it.
Type–converting comparison (like ==) can have suprising results. You are encouraged to avoid using them and use strict comparision (like ===
and !==
) instead.
Code inside promises that fails will not throw to the console. This can lead to bugs going undetected, so always add a rejection handler.
myPromise().then(doSomething).catch(function(e) { throw e; });
Use always curly braces, also for single line statements.
Not using curly braces to mark blocks can lead to subtle erros and introduces a new style (which readers will have to parse)
if (bla) {
foo();
} else {
fooToo();
}
Keywords or special characters require you to use quotes sometimes, so make code easier to read and to avoid errors prefer to always use single quotes like other strings.
var obj = {
'foo': bar,
'fooToo': 'string',
'js is great': true
}