@@ -229,4 +229,150 @@ Uma sugestão de sintaxe para escrever os comentários é o do [JSDuck](https://
229229
230230## Variables
231231
232+ Sempre use ` const ` ou ` let ` para declarar variáveis. Senão irá resultar em variáveis globais.
233+
234+ ``` javascript
235+ // Good
236+ const gallery = new Gallery ();
237+
238+ // Bad
239+ gallery = new Gallery ();
240+ ```
241+
242+ Use a declaração ` const ` ou ` let ` , por variável.
243+
244+ ``` javascript
245+ // Good
246+ const items = getItems ();
247+ const name = ' name' ;
248+ const status = ' open' ;
249+
250+ // Bad
251+ const items = getItems (),
252+ name = ' name' ,
253+ status = ' open' ;
254+ ```
255+
256+ Agrupe as suas ` const ` e em seguida, as ` let ` s.
257+
258+ ``` javascript
259+ // Good
260+ const status = true ;
261+ const items = getItems ();
262+ let name;
263+ let i;
264+ let length;
265+
266+ // Bad
267+ let i, len, status,
268+ items = getItems (),
269+ status = true ;
270+
271+ // Bad
272+ let i;
273+ const items = getItems ();
274+ let status;
275+ const status = true ;
276+ let len;
277+ ```
278+
279+ Crie as variáveis onde precise das mesmas.
280+
281+ ``` javascript
282+ // Good
283+ function checkName (hasName ) {
284+ if (hasName === ' test' ) {
285+ return false ;
286+ }
287+
288+ const name = getName ();
289+
290+ if (name === ' test' ) {
291+ this .setName (' ' );
292+ return false ;
293+ }
294+
295+ return name;
296+ }
297+
298+ // Bad - unnecessary function call
299+ function checkName (hasName ) {
300+ const name = getName ();
301+
302+ if (hasName === ' test' ) {
303+ return false ;
304+ }
305+
306+ if (name === ' test' ) {
307+ this .setName (' ' );
308+ return false ;
309+ }
310+
311+ return name;
312+ }
313+ ```
314+
315+ Não faça atribuições de variáveis em cadeia. Ao encadear atribuições de variáveis , se cria variáveis globais implícitas.
316+
317+ ``` javascript
318+ // Good
319+ (function example () {
320+ let a = 1 ;
321+ let b = a;
322+ let c = a;
323+ }());
324+
325+ console .log (a); // undefined
326+ console .log (b); // undefined
327+ console .log (c); // undefined
328+
329+ // the same applies for `const`
330+
331+ // Bad
332+ (function example () {
333+ // JavaScript interprets this as
334+ // let a = ( b = ( c = 1 ) );
335+ // The let keyword only applies to variable a; variables b and c become
336+ // global variables.
337+ let a = b = c = 1 ;
338+ }());
339+
340+ console .log (a); // undefined
341+ console .log (b); // 1
342+ console .log (c); // 1
343+ ```
344+
345+ Evitar o uso de incrementos e decrementos unários (++, --).
346+
347+ ``` javascript
348+ // Good
349+ let array = [1 , 2 , 3 ];
350+ let num = 1 ;
351+ let increment = num += 1 ;
352+ let decrement = num -= 1 ;
353+
354+ array .forEach ((value ) => {
355+ value += 1 ;
356+ });
357+
358+ // Bad
359+ let array = [1 , 2 , 3 ];
360+ let num = 1 ;
361+ let increment = num ++ ;
362+ let decrement = -- num;
363+
364+ for (let i = 0 ; i < array .length ; i++ ){
365+ let value = array[i];
366+ ++ value;
367+ }
368+ ```
369+
370+ ** [ ⬆ voltar ao topo] ( #summary ) **
371+
232372## Performance
373+
374+ ``` javascript
375+
376+ ```
377+
378+ ** [ ⬆ voltar ao topo] ( #summary ) **
0 commit comments