Coding conventions are guidelines for programming style, typically covering:
Coding conventions help ensure quality by:
These conventions can be formalized as documented rules for teams to follow or serve as personal coding practices.
At code7school, we use camelCase for naming identifiers (such as variables and functions).
All names begin with a letter.
Further details about naming rules can be found at the bottom of this page.
firstName = “John”; lastName = “Doe”; price = 19.90; tax = 0.20; fullPrice = price + (price * tax); |
Always include spaces around operators (e.g., =, +, -, *, /) and after commas.
let x = y + z; const myArray = [“Volvo”, “Saab”, “Fiat”]; |
Always use 2 spaces for indenting code blocks.
function toCelsius(fahrenheit) { return (5 / 9) * (fahrenheit – 32); } |
General rules for simple statements:
Always terminate a simple statement with a semicolon.
const cars = [“Volvo”, “Saab”, “Fiat”]; const person = { firstName: “John”, lastName: “Doe”, age: 50, eyeColor: “blue” }; |
General rules for complex (compound) statements:
function toCelsius(fahrenheit) { return (5 / 9) * (fahrenheit – 32); } |
for (let i = 0; i < 5; i++) { x += i; } |
if (time < 20) { greeting = “Good day”; } else { greeting = “Good evening”; } |
General rules for defining objects:
const person = { firstName: “John”, lastName: “Doe”, age: 50, eyeColor: “blue” }; |
Short objects can be written on a single line, with spaces between properties, like this:
const person = {firstName:“John”, lastName:“Doe”, age:50, eyeColor:“blue”}; |