From the course: JavaScript: Best Practices for Code Formatting

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Space before and after operators

Space before and after operators - JavaScript Tutorial

From the course: JavaScript: Best Practices for Code Formatting

Start my 1-month free trial

Space before and after operators

- [Instructor] You've probably been using operators like plus, minus and equals since your earliest math courses. And it's unlikely your teachers ever required a particular spacing regimen around them. And like most of Javascript, white space isn't significant around operators. So there's no requirement to write equations or concatenations in any specific way. However, spaces help human readability in many parts of code, and operators are no exception. To make your code more readable, you should include a space before and after every operator. Including mathematical, logical, and assignment operators. In the code for my app, I've coded up a function to calculate the distance between two sets of geo coordinates. I didn't use any spaces around operators, and the statements are pretty dense. ESLint supports flagging missing spaces with the space-infix-ops rule. An infix operator is an operator that's used between two…

Contents