Skip to content

Latest commit

 

History

History
32 lines (24 loc) · 663 Bytes

single-line-comments.md

File metadata and controls

32 lines (24 loc) · 663 Bytes

Single Line Comments

Use slashes for single line comments that help clarify difficult segments of your code. Don't use comments for trivial things.

JavaScript

Right:

// 'ID_SOMETHING=VALUE' -> ['ID_SOMETHING=VALUE', 'SOMETHING', 'VALUE']
var matches = item.match(/ID_([^\n]+)=([^\n]+)/);

var isSessionValid = (session.expires < Date.now());
if (isSessionValid) {
  // ...
}

Wrong:

// Execute a regex
var matches = item.match(/ID_([^\n]+)=([^\n]+)/);

// Check if the session is valid
var isSessionValid = (session.expires < Date.now());
// If the session is valid
if (isSessionValid) {
  // ...
}