So now did we know about typescript fundamentals and how it differs and all is related to JavaScript.
Let's dig a bit deeper into the different core types typescript knows the number is the type we see
here.
And as I explained there is no difference between integers like the five here and floats or doubles
as it would be called in other programming languages like the 2.8 here.
Indeed in JavaScript and the same is true in typescript all numbers are floats by default.
So for JavaScript and dev for all of our typescript there is no difference between 5 like this and 5
like this it's the same number essentially.
Now besides numbers we all to have other core types and that would be strings.
So text and boolean is let's all to have a look at those we actually saw.
All of those in action here in this if statement already which we learned is a bit redundant.
Nonetheless this here would be a string although of course 5 with quotes would be a string because it's
text and the result for example of this comparison here.
That would be a boolean this operator the triple equals sign or the negated equality operator here that
produces True or false.
And of course we can ever produce it dynamically enough if check which we'll of do or we initialize
a variable with a true or false value.
So let's do both here.
Here we could add a new constant print result and set this to true for example.
And just to make it really clear this could be a variable as well it doesn't have to be constant can
be a variable which you would create with let in JavaScript.
But since I don't plan on changing it here I'll go with a constant and we could pass this as a third
parameter here.
Let's say we pass in print result which holds true here.
Now we immediately get an error of course because our add function does not support a third argument.
We see expect the two arguments but got three.
So therefore we have to make sure we support a third argument.
And there we could add a show resolve parameter you could name it print or assault here as well.
I'm going with show result to a wide confusion regarding the naming but technically these two names
would not clash.
So here I'll name it shall result.
And I want to make sure that this is of type boolean by setting this to boolean again by adding a colon
after the parameter here and then by adding the name of the type.
Now this function accepts does and now what we can do is we can add a if check here and check if show
result.
If this is true we can of current course compare it to true but as you know in JavaScript you can all
just pass in the true or false C value here and JavaScript Bill evaluated and if this yields true somehow
or a truth value in general then we'll make it entity of block.
Otherwise we won't.
And let's say we do make it in here and then I want to console log and 1 plus and 2 otherwise in the
Ellis case if we don't make it in there then I want to return this.
So now does is a function which sometimes returns a value and sometimes does not return a value but
output it immediately.
Now you could argue if you want to write such a function which is kind of unpredictable or which might
behave unexpectedly if you are passing and true here.
But here we're doing it.
So this function only sometimes returns sometimes it also does not return but instead just locks something
to the console.
Now here we can't actually call at just like this and don't need to store it in result and don't need
to console log result because with print result set to true at itself.
So the function itself will print the result.
Hence if you know saved it and we recompile our apt yes file here with the TSC command.
Once this is done the page will reload and we still see our output here.
But now it's coming from line 6.
And if we have a look.
Line 6 is indeed inside the function.
So this is a boolean.
Now let's say we want to customize the output and therefore we have a result phrase constant here where
we say result is colon and then some whitespace and we pass that in as foo as well with result Frasier.
Well then we could expect this as an argument here as well phrase which should be of type String.
By adding a colon and then string is the name of the type.
And now we could use that phrase to output it as part of our result output.
If we're printing the result right into function so then here we could have phrased plus and 1 plus
and 2 and if we do that and we recompile by repeating that command we'll see that this phrase is part
of the result but we also now reintroduce the old back because I have a string which I combined with
two numbers.
Everything is converted to a string here and that's not what I want to a white does in this function.
We could add a result variable here or a result constant and store our result here.
This will now be treated in a mathematical way because only numbers are involved and then a heater.
We could combine that with phrase or just return it.
And now since this is never directly calculated to gather with a string this will always be a number.
And yes then here does number of combined with a string will be converted to a string.
But since the mathematical calculation finished before that will have the right result.
So now if repeat dad at a recompile we get the right output.
So now these are the core data types and action.
Let's now make sure we fully understand how types are assigned and also why we don't explicitly assign
types down there.