Whitespace
Published Jun 16, 2022Updated Oct 26, 2022
Contribute to Docs
In programming, whitespace uses horizontal and vertical space characters or blank lines to format code and improve readability.
Example
The code example below is hard to read since there is little to no whitespace. It also does not have indentation with spaces so people can not easily see what is nested within what.
function createRangeIterator(min = 0, max = Infinity, step = 1) {let nextNum = min;let numCount = 0;const rangeIterator = {next: function () {let result;if (nextNum < max) {result = { value: nextNum, done: false };nextNum += step;numCount++;return result;}return { value: numCount, done: true };},};return rangeIterator;}
When whitespace is used, the code is much more readable:
function createRangeIterator(min = 0, max = Infinity, step = 1) {let nextNum = min;let numCount = 0;const rangeIterator = {next: function () {let result;if (nextNum < max) {result = { value: nextNum, done: false };nextNum += step;numCount++;return result;}return { value: numCount, done: true };},};return rangeIterator;}
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn more on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours