Loading...
(function(){<br />
let canvas = document.createElement('canvas'),<br />
ctx = canvas.getContext('2d'),<br />
w = canvas.width = innerWidth,<br />
h = canvas.height = innerHeight,<br />
particles = [],<br />
properties = {<br />
bgColor : 'rgba(17, 17, 19, 1)',<br />
particleColor : 'rgba(255, 40, 40, 1)',<br />
particleRadius : 3,<br />
particleCount : 60,<br />
particleMaxVelocity : 0.5,<br />
lineLength : 150,<br />
particleLife : 6,<br />
};<br />
<br />
document.querySelector('body').appendChild(canvas);<br />
<br />
window.onresize = function() {<br />
w = canvas.width = innerWidth;<br />
h = canvas.height = innerHeight;<br />
}<br />
<br />
class Particle {<br />
constructor() {<br />
this.x = Math.random()*w;<br />Loading...
Section notes from the book: JavaScript: The Definitive Guide by David Flanagan
The semicolon (;) in JavaScript is used to separate statements from one another. Some programmers use semicolons to explicitly mark the end of statements, even when they are not required, while others omit semicolons whenever possible.
In the latter case, you should be careful, because the JavaScript interpreter does not treat every line break as a semicolon.
The JavaScript interpreter treats a line break as a semicolon if the next non-whitespace character cannot be interpreted as a continuation of the current statement.
Let’s look at the following example:
1let x2x3=485console.log(x)67// the JavaScript interpreter will interpret it as:8let x; x = 8; console.log(x);
The interpreter cannot parse the code let x x without a semicolon. The second line break is treated differently because the interpreter can continue parsing it as part of a longer statement, such as a = 3;.
The following example looks like two separate statements separated by a newline:
1let a = b + c2(d+l).toString()
However, the parentheses on the second line can be interpreted as a function call on the value from the first line. As a result, the JavaScript interpreter treats the code as follows:
1let a = b + c(d+l).toString()
To avoid problems like this, you should use a semicolon if the next statement begins with one of the following characters: (, [, /, +, or -.
If you cannot place a semicolon at the end of the previous statement, you can instead use a defensive semicolon at the beginning of the potentially ambiguous statement.
1let n = 0 // The semicolon is omitted here.2;[y, y + 2, y + 4].forEach(console.log) // The defensive semicolon keeps this statement separate.
A line break is always interpreted as a semicolon in the following cases:
return, throw, yield, break, and continue statements.++ and -- operators. If you use either of these operators in their postfix form, they must appear on the same line as the expression they apply to.=> token must appear on the same line as the parameter list.