In this video we will talk about JavaScript expression and statement.
We are moving away from normal react to normal JavaScript because understanding expression and statement
in react is really very important.
Okay, cool.
So you can see that all what we are learning is adding more things to a component.
Now we've added gsx to a component in this video.
We will talk about also how you can add expression to your component.
So let's go ahead and do more.
What is expression and statements?
So we are going to write normal JavaScript file on this component because React is JavaScript, right?
So we can write valid JavaScript file here, whether inside my function here or outside here.
Are we all to go?
So try it out.
Let's try to elect something and see if it be called normal JavaScript API elect and indeed it has been
elected like that.
So now I can see that I can write normal JavaScript here.
So back to business.
Have some space here.
So differences.
Between.
Expression and.
Statement.
All right, so let's define it in JavaScript.
There are two key ways to create a code, whether expression or statement.
Each has its own purpose and syntax.
Well, two differences.
Here we go.
An expression is a piece of code that produces a value.
Simple.
A piece of code that produces a value.
It can be a single value, like a number or string, or it can be more complex, like an array or object.
And expressions, on the other hand, are often used in assignment.
Okay, so let's have a look at the example of statement.
Remember, sorry, expression.
Expression again produces what a value.
So let's say that if I say let's age is equal to 42, this is expression because it's true.
This is what a value if I console.log h.
Let's check our terminal.
Our browser here.
Console.
Open it.
And now let's have a look.
I have.
I have the refresh refreshed.
I have 42 being console.log.
So this is what is called expression.
And I can write, let's say I mean const.
Sum is equal to two plus two plus two.
This is what this what you call expression, because it's this is what a single value or I can produce
an array of numbers is also what a expression.
So what is a statement?
A statement is a piece of code that does not produces a value statement, are used to create blocks
of code like if statements or for loop.
So let me create example of statements here.
So a statement here is that.
So let's declare a value for money.
Let's say it's equal to $20 here.
And now let's check.
So if.
The money you have is less than 100.
Then we can console, look something and say that you are broke.
Okay.
So let's see if I check the terminal.
Indeed I have.
You are blocked.
Okay, I forgot D.
Okay.
Don't worry about it, grandma.
Here.
So that is statement.
You can see that a statement is.
Is used to create a blocks of code like this one.
Right.
It checks is often used with if statement and you talk about itinerary or operator here and I mean react,
which is crucial crucial crucial for you to understand about ternary operator here the takeaway here
is understand how X sorry the difference between expression and I mean statement.
The next video you talk about how we can embed expressions in js x.