Created
July 12, 2023 16:17
-
-
Save prof3ssorSt3v3/74c6a20e51a1047293cf7fce1775d55e to your computer and use it in GitHub Desktop.
The difference between expressions and statements
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
JS Expressions vs Statements | |
Expressions => returns a value | |
Statements => complete task instruction. | |
*/ | |
123 //expression | |
1+ 1 //expression | |
"hello" //expression | |
true //expression | |
[1, 2, 3] //expression | |
// value - held in a variable | |
let f = function(){} //statement | |
f(); //expression | |
//IIFE - expression | |
(function(){})(); | |
//ternary operator - expression | |
let alive = isAlive ? 1 : 0 | |
if( isAlive === 1){ } // - statement | |
for(){} // statement | |
console.log() // expressions only | |
function APP(){ | |
//React | |
return ( | |
<div> | |
<p>{1 + 1}</p> | |
<p>{isAlive ? 1 : 0}</p> //success - expression | |
<p>{if(isAlive===1){}}</p> //fails - statement | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment