27
loading...
This website collects cookies to deliver better user experience
And my heart glows bright red under my filmy, translucent skin and they have to administer 10cc of JavaScript to get me to come back. (I respond well to toxins in the blood.) Man, that stuff will kick the peaches right out your gills!
22
is an expression. "hello world"
is an expression. Within a line of code, there can be multiple expressions. With that said, the line of code itself would be a statement. 1
is an expression, 1;
is a statement.;
to denote the end of a statement, so sometimes, you can omit explicit statements for implicit ones.1;
. But these statements aren't interesting; they are useless. Interesting statements affect something. Have an impact on its world. They could display something on the screen or update the state of a program. These statements can impact other statements, creating what is known as side effects.useEffect
. I always thought side effects were something that the React developers referenced. It's much more than that. A side effect is simply a statement containing an action or result that could impact other statements.let
or var
makes sense with this definition. Using the keyword const
does not fit this definition. Another way I was taught variables was by thinking about them as boxes. You are designating boxes for data you want to store and use later. If you need that data, you open up the box.let ten = 10
. ten
doesn't unpack and reveal the data 10
. What it does is it returns you the number 10
that it references.10
is saved in memory once, and both ten
and anotherTen
variables reference the number. Same with the string example.let ten = 10;
let anotherTen = 10;
console.log(ten === anotherTen); // true; they are equal
let word = 'hello';
let anotherWord = 'hello';
console.log(word === anotherWord); // true
let yourName;
do {
yourName = prompt('what is your name?');
} while (!yourName);
do, while
loops, but it's good to remember as a reference. Another thing about loops, specifically traditional for
loops, is that they must contain two semicolons. I write the usual syntax so frequently that I never contemplated why I needed the semicolons in the loops. Well, the statement before the first semicolon is an expression or variable declaration. After the first semicolon, we have the condition, an expression that is evaluated before each loop iteration. Lastly we have the final expression, which will be evaluated at the end of each loop iteration.//Notice empty space v -- we don't set a condition so it can run forever if we let it
for (let current = 20; ; current = current + 1) {
if (current % 7 == 0) {
console.log(current);
break;
}
}
var i = 0;
for (;;) {
if (i > 3) break; // we need the break statement, and still need the two semicolons!
console.log(i);
i++;
}
// print fizzBuzz from 1..n
function fizzBuzz(count) {
for (let i = 1; i <= count; i++) {
if (i % 15 === 0) console.log('FizzBuzz');
else if (i % 3 === 0) console.log('Fizz');
else if (i % 5 === 0) console.log('Buzz');
else console.log(i);
}
}
function fizzBuzz(count) {
for (let i = 1; i <= count; i++) {
let word = '';
if (i % 3 === 0) word += 'Fizz';
if (i % 5 === 0) word += 'Buzz';
console.log(word || i);
}
}