You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Always use the same naming convention for all your code. For example:
23
-
***
24
23
1. Do use camelCasing for variable and function arguments names;
25
24
2. Do use PascalCasing for function names and global variable;
26
25
3. Constants (like PI) written in UPPERCASE;
27
26
4. Do not use under_scores in variable, constants, function arguments or function names;
28
27
5. Do not use hyphens in JavaScript names.
29
-
***
30
28
31
-
## Naming Conventions
29
+
30
+
### Naming Conventions
32
31
33
32
Do use PascalCasing for function names:
34
33
35
34
```javascript
36
-
functionHelloWorld()
37
-
{
38
-
}
35
+
functionHelloWorld()
36
+
{
37
+
}
39
38
```
40
39
41
40
Do use camelCasing for function arguments and local variables:
42
41
43
-
function Hello(isShow)
44
-
{
45
-
}
42
+
```javascript
43
+
functionHello(isShow)
44
+
{
45
+
}
46
46
47
47
firstName ="John";
48
-
lastName = "Doe";
49
-
50
-
price = 19.90;
51
-
discount = 0.10;
52
-
53
-
fullPrice = price * 100 / discount;
48
+
lastName ="Doe";
49
+
50
+
price =19.90;
51
+
discount =0.10;
52
+
53
+
fullPrice = price *100/ discount;
54
+
```
54
55
55
-
***Note: Don't start names with a $ sign. It will put you in conflict with many JavaScript library names.***
56
+
*Note: Don't start names with a $ sign. It will put you in conflict with many JavaScript library names.*
56
57
57
58
#### Spaces Around Operators
58
59
@@ -63,113 +64,130 @@ Examples:
63
64
var x = y + z;
64
65
var values = ["Volvo", "Saab", "Fiat"];
65
66
66
-
####Code Indentation
67
+
### Code Indentation
67
68
68
69
Always use 4 spaces for indentation of code blocks:
69
70
70
71
Functions:
71
72
72
-
function ToCelsius(fahrenheit)
73
-
{
74
-
return (5/9) * (fahrenheit-32);
75
-
}
73
+
```javascript
74
+
functionToCelsius(fahrenheit)
75
+
{
76
+
return (5/9) * (fahrenheit-32);
77
+
}
78
+
```
76
79
77
-
***Note: Do not use tabs (tabulators) for indentation. Text editors interpret tabs differently.***
80
+
*Note: Do not use tabs (tabulators) for indentation. Text editors interpret tabs differently.*
78
81
79
-
####Statement Rules
82
+
### Statement Rules
80
83
81
84
*General rules for simple statements: Always end simple statement with a semicolon.*
82
85
83
86
Examples:
84
-
85
-
var values = ["Volvo", "Saab", "Fiat"];
86
-
87
-
var person = {
88
-
firstName: "John",
89
-
lastName: "Doe",
90
-
age: 50,
91
-
eyeColor: "blue"
92
-
};
93
-
94
-
#### General rules for complex (compound) statements:
95
-
***
87
+
88
+
```javascript
89
+
var values = ["Volvo", "Saab", "Fiat"];
90
+
91
+
var person = {
92
+
firstName:"John",
93
+
lastName:"Doe",
94
+
age:50,
95
+
eyeColor:"blue"
96
+
};
97
+
```
98
+
99
+
### General rules for complex (compound) statements:
100
+
96
101
1. Put the opening bracket at the end of the first line.
97
102
2. Use one space before the opening bracket.
98
103
3. Put the closing bracket on a new line, without leading spaces.
99
104
4. Do not end complex statement with a semicolon.
100
-
***
101
105
102
106
Functions:
103
107
104
-
function toCelsius(fahrenheit) {
105
-
return (5/9) * (fahrenheit-32);
106
-
}
108
+
```javascript
109
+
functiontoCelsius(fahrenheit) {
110
+
return (5/9) * (fahrenheit-32);
111
+
}
112
+
```
107
113
108
114
Loops:
109
115
116
+
```javascript
110
117
for (i =0; i <5; i++) {
111
118
x += i;
112
119
}
113
-
120
+
```
114
121
115
122
Conditionals:
116
123
117
-
if (time < 20) {
118
-
greeting = "Good day";
119
-
} else {
120
-
greeting = "Good evening";
121
-
}
124
+
```javascript
125
+
if (time <20) {
126
+
greeting ="Good day";
127
+
} else {
128
+
greeting ="Good evening";
129
+
}
130
+
```
122
131
123
132
124
-
####Object Rules
133
+
### Object Rules
125
134
126
135
General rules for object definitions:
127
-
***
136
+
128
137
1. Place the opening bracket on the same line as the object name.
129
138
2. Use colon plus one space between each property and it's value.
130
139
3. Use quotes around string values, not around numeric values.
131
140
4. Do not add a comma after the last property-value pair.
132
141
5. Place the closing bracket, on a new line, without leading spaces.
133
142
6. Always end an object definition with a semicolon.
134
-
***
143
+
135
144
Example:
136
145
137
-
var person = {
138
-
firstName: "John",
139
-
lastName: "Doe",
140
-
age: 50,
141
-
eyeColor: "blue"
142
-
};
146
+
```javascript
147
+
var person = {
148
+
firstName:"John",
149
+
lastName:"Doe",
150
+
age:50,
151
+
eyeColor:"blue"
152
+
};
153
+
```
143
154
144
155
Short objects can be written compressed, on one line, like this:
145
156
146
-
var person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};
157
+
```javascript
158
+
var person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};
159
+
```
147
160
148
-
***Line Length < 80***
161
+
### Line Length < 80
149
162
150
163
For readability, avoid lines longer than 80 characters. If a JavaScript statement does not fit on one line, the best place to break it, is after an operator or a comma.
0 commit comments