Home › JavaScript Tutorial › JS style guide
JS style guide
Habits for readable code.
Use meaningful camelCase names, const by default, ===, small functions, consistent indentation, and comments that explain why.
Commands in this lesson
const
Definition: Declares a variable that cannot be reassigned.
Syntax:
const name = value;
Example:
const pi = 3.14;
console.log(pi);Example code
<pre id='o'></pre>
<script>
const MAX_ITEMS=3;
function totalPrice(prices){return prices.slice(0,MAX_ITEMS).reduce((sum,p)=>sum+p,0);}
o.textContent=totalPrice([10,20,30,40]);
</script>