
postfix/prefix forms
let i = 0;
while(++i < 5) alert (i)
// prefix = first 1 last 4
while(i++ < 5) alert (i)
// postfix = first 1, last 5
for (let i = 0; i < 5; i++) alert(i);
for(let i = 0; i < 5; ++i;) alert(i);
/*no different
* for statement last execute step(++i, i++)
*/
for(i=1; i <= 10; i++){
if(i % 2 == 0) {
alert(i)
}
}
Output prime numbers
link - find it prime number from under the typing number
The syntax
switch(x) {
case 'value': // if (x === 'value1)
...
[break]
case 'value2': // if (x === 'value2')
...
[break]
default:
...
[break]
}
grouping of “case”
//want the same code to run for case 3 and case 5
case 3:
case 5:
alert('Wrong!');
alert("Why don't you take a math class?");
break;
Type matter
case valus check strictly eqaul ===
let arg = prompt("Enter a value?");
switch (arg) {
case 3:
alert( 'Never executes!' );
break;
}
/*the result of the prompt is a sting
* which is not strictly eqaul === to the number 3
* So It's dead code case 3
*/
sometimes don’t require break in last case but recomment to use it for code future-proof.
other
shift + alt + A _link