Skip to content

Instantly share code, notes, and snippets.

@prof3ssorSt3v3
Created July 12, 2023 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prof3ssorSt3v3/74c6a20e51a1047293cf7fce1775d55e to your computer and use it in GitHub Desktop.
Save prof3ssorSt3v3/74c6a20e51a1047293cf7fce1775d55e to your computer and use it in GitHub Desktop.
The difference between expressions and statements
/*
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