So what is Times called What is it all about why would we use it typescript is a javascript superset.
Now what does this mean.
It means that typescript is in the end a language a programming language.
Building up on javascript it's not a brand new language.
Instead it takes the javascript language and adds new features and advantages to it.
It makes writing javascript code easier and more powerful.
You could say but we have one huge disadvantage typescript can't be executed by javascript environments
like the browser browsers can't execute TypeScript and for example note J.S. also can't execute typescript
soda environments where we can execute javascript don't support typescript.
What's the idea behind typescript then it's a better version of JavaScript and we can't use it.
Well not quite typescript is a programming language but it's also a tool.
It's a powerful compiler which you run over your code to compile your typescript code to javascript.
So what you get as a result when writing code in typescript is javascript but you didn't write that
JavaScript code you wrote typescript code with all the new features and all the advantages and you get
normal javascript code.
Well that of course brings up one important question how can typescript add new features if what you
get in the end is regular javascript.
And the answer is the typescript compiler compiles these new features to JavaScript work arounds.
So in the end it might give you a nicer syntax an easier way of doing something and it will then compile
that nicer easier way to a more complex javascript snippet which you would have to write otherwise so
it's not magic.
Of course it can't add what's not possible at all in the javascript language but it can add new features
that simply are easier to use nicer syntax things like this.
In addition types of course does one important thing which the name already implies.
It adds types it adds a feature to these javascript language add which will have a close look in a second
which will actually give you as a developer an opportunity of identifying errors in your code earlier
before your script runs and the error occurs at runtime in the browser.
So it does not only give you some new features and nicer ways of doing something.
It also gives you extra error checking where errors which you would otherwise get as runtime errors
can be caught and fixed early during development.
So why would we use typescript consider disk sample a fairly simple javascript function which adds to
numbers.
Now when I call it please notice that I'm passing in two strings instead of two numbers and I'll show
you a real example where it's something like this could happen realistically in just a second.
So we're calling this function with two strings and as a result what you would actually get here is
probably an unwanted behavior because if you add two strings javascript will come candidate the strings
instead of doing a mathematical calculation here.
So the result would not be 5 but 20 free concatenated string of the two numbers.
This is an error you could have in JavaScript.
It's not a technical error.
You probably won't get a runtime error but you have a logical mistake in your code and that of course
can lead to huge problems in the web applications you're writing with JavaScript.
Now of course in JavaScript we have mitigation strategies.
We could add an if check in the function to check the types of DB inputs at runtime.
We could also validate and sanitize user input and whilst we might want to do all of that it would also
be nice if we could catch errors like this during development already.
And thankfully this is possible with typescript because developers can write invalid code here and introduce
bugs like this in javascript and with typescript we have a tool that helps us write better code and
avoid such problems.
So let's have a closer look at this.