Variable names have to be meaningful. (Don't name it as "abc, i, a, b")
Method:
- use camelCase with a lowercase first letter (
index, obj, getName, setName)
Object:
- use camelCase with a lowercase first letter (
index, obj, getName, setName)
- Place the opening bracket on the same line as the object name.
- Use colon plus one space between each property and its value.
- Use quotes around string values, not around numeric values.
- Do not add a comma after the last property-value pair.
- Place the closing bracket on a new line, without leading spaces.
- Always end an object definition with a semicolon.
const person = {
firstName: "John",
lastName: "Doe",
age: 50,
eyeColor: "blue"
};
Class:
- camel case (
Person, Student, Tutor)
Constant:
- uppercase (
NUMBER, PLAYER, ABC, PLAYER_NUMBER)
Use lambda if it could be used:
var setStudent = (name,age) => {
age +=1;
return "name:" + name + ",age:" + age;
}
// Parentheses can be omitted when there is only one parameter
var setStudent = age => {
age +=1;
return "age: " + age;
}