The Difference between JS Expressions and Statements

  Рет қаралды 6,527

Steve Griffith - Prof3ssorSt3v3

Steve Griffith - Prof3ssorSt3v3

Күн бұрын

Пікірлер: 35
@uchennachukwuba
@uchennachukwuba 8 ай бұрын
Only 29 comments? This channel is the most underrated I’ve ever come across. Clear and concise
@AhmadJubair
@AhmadJubair Жыл бұрын
Thanks for the clear-cut explanation, Steve. I've been working with Reactjs for some time but still had a bit of confusion about the differences between these two. Understood now.
@AlazTetik
@AlazTetik Жыл бұрын
Yet again, great and useful summary!
@shahinza
@shahinza Жыл бұрын
Thank you professor.
@alisahi8bp10
@alisahi8bp10 10 ай бұрын
After learning fundamentals of JS & ReactJS from John Smilga (Codding Addict). I was looking for someone who can give a deeper dive into the JS concepts.. And Steve fullfilled everything i was looking forward... All i can say is Thankyou for ur service.
@bapi6060
@bapi6060 Жыл бұрын
Really great explanations!
@bostongreen1629
@bostongreen1629 3 ай бұрын
WOW, I guarantee this will decode makes sense of a lot of concepts when working with JS. BRAVO, the way you explain it
@MutalibGozalov
@MutalibGozalov 8 ай бұрын
Awesome explanation, thanks
@s1gma9000
@s1gma9000 6 ай бұрын
killer video, u saved me time!!
@traininfobd
@traininfobd Жыл бұрын
Sir, if assigning a value like a number is an expression but why assigning a ternary operator is a statement? var num=343; //Expression var alive= isAlive?1:0 / statement chatGPT says these are expression , var x = 5; // assignment expression var y = x + 3; // arithmetic expression ?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 Жыл бұрын
The ternary part is an expression. Once you add the var alive = it becomes a statement
@detaaditya6237
@detaaditya6237 10 ай бұрын
Hi professor, thanks for the explaination! I want to ask about this part: let x = function(){}. You explained that this is an statement. Are you referring to the whole line or only the `function(){}` part? Because `function(){}` seems to work differently when it is standalone vs when assigned to a variable or parameter of another function. When standalone, it seems like it behaves like a statement. But when it is assigned, it returns the function value - which makes it behave like an expression. Is this true? Please correct me if I'm wrong sir. Once again, thanks a lot!
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 10 ай бұрын
the whole line let x = function () { } is a statement. function ( ) { } is an expression. It is a value that you could put into a variable. If you wrap it in a set of parentheses and put another set after it then it becomes an IIFE Immediately Invoked Function Expression. you could place function ( ) { } inside a console.log( ) without an error. That's a good indication that it is an expression.
@mehdi-vl5nn
@mehdi-vl5nn Жыл бұрын
like many other topics in the world of programming languages, is heavily dependent on the language designers' interpretation of meanings. Your example: const getRectArea = function(width, height) { return width * height; }; is actually a Function expression in JavaScript, where functions are objects themselves. Another example can be found in JavaScript's Promises, which are often equated with Futures in other languages but are actually coroutines. A funny example from the world of Python is that Tasks are actually Futures.
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 Жыл бұрын
Dart is a good example. They have Futures instead of Promises.
@Truth_Taken
@Truth_Taken Жыл бұрын
great and simple explanation.
@MarstonH
@MarstonH 7 ай бұрын
🔥
@apex-lazer
@apex-lazer 11 ай бұрын
Thank you again!
@Denis_Victorious
@Denis_Victorious Жыл бұрын
Actually thanks for your awesome content, but I got a bit confused at this one. Why has been stuff like "let f = function(){}" called a Function Expression (according to MDN docs for example), whereas turns out it's a statement (according to the video)🤔
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 Жыл бұрын
Here you go: function bob( ) { //this is a function declaration which includes a name and starts with the keyword function //gets hoisted with its identifier `bob` } const bob = function ( ) { //this is a function expression //which is part of a statement //`bob` gets hoisted but not the function } ( function ( ) { //this is an IIFE //immediately invoked function expression //not hoisted //but run as soon as it is encountered })( )
@Denis_Victorious
@Denis_Victorious Жыл бұрын
@@SteveGriffith-Prof3ssorSt3v3 I've got it eventually, thanks! Turns out I had false assumption about hoisting. I didn't realize let/const get hoisted too, only they don't get initialized in advance (in comparison with var/funcDeclarations) P.S.: I've just noticed your reply (due to my off comments notifications)
@zidan3948
@zidan3948 Жыл бұрын
Is it safe to say that whatever starts with a keyword is a statement?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 Жыл бұрын
Almost. Some keywords are values. Eg true false null this.
@zidan3948
@zidan3948 Жыл бұрын
@@SteveGriffith-Prof3ssorSt3v3 I think I get it now, thanks a lot!!
@Sonu_Kr95
@Sonu_Kr95 Жыл бұрын
Thanks
@Stoney_Eagle
@Stoney_Eagle Жыл бұрын
So basically all I have to think of is "Can I fit this in a jsx return", basically I now never have to think about it again. neat☺
@barungh
@barungh Жыл бұрын
When I come to KZbin, first thing I search for is your new video 🙂
@Strasbourgeois
@Strasbourgeois Жыл бұрын
let f = function(){} is a statement that doesn't start with the keyword function but has a function definition within it. So it is a function expression. Am I right? Love your videos very much
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 Жыл бұрын
Yes. That is correct
@KurkoVarangian-kg2zj
@KurkoVarangian-kg2zj 5 ай бұрын
This channel has hands down the best explanations
@chhavimanichoubey9437
@chhavimanichoubey9437 Жыл бұрын
Interview question no doubt
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 Жыл бұрын
And valuable info for solving a common problem in React.
@igorr4682
@igorr4682 Жыл бұрын
and you can have an expression inside the statement as well. In summary, expressions produce values, while statements perform actions or control the flow of a code
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 Жыл бұрын
Yes. A statement can contain an expression but not the other way around.
@ВолодимирДжичко
@ВолодимирДжичко Жыл бұрын
Thanks ❤
Checking for the Existence of JavaScript Variables
9:08
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 3,4 М.
Html Css JavaScript Navigator MediaDevices Take A Picture App.
14:33
sitowebveloce
Рет қаралды 1,9 М.
Incredible: Teacher builds airplane to teach kids behavior! #shorts
00:32
Fabiosa Stories
Рет қаралды 11 МЛН
Как мы играем в игры 😂
00:20
МЯТНАЯ ФАНТА
Рет қаралды 3,3 МЛН
Officer Rabbit is so bad. He made Luffy deaf. #funny #supersiblings #comedy
00:18
Funny superhero siblings
Рет қаралды 13 МЛН
Important differences between textContent and innerText
11:44
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 2,4 М.
Deep Dive into Array from method
22:05
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 2,7 М.
Understanding the Event Loop Sequence of Tasks
13:30
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 5 М.
JavaScript: How It's Made
10:54
Fireship
Рет қаралды 881 М.
Iterable vs Enumerable in JavaScript
9:15
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 20 М.
Expressions vs statements in JavaScript, know the difference
4:38
Revealing the Differences between HTML Dialogs and the Popover API
24:14
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 9 М.
The difference between an expression and a statement in JavaScript
16:24
Being Competent With Coding Is More Fun
11:13
TheVimeagen
Рет қаралды 85 М.