Hey guys, welcome to intellipaat and we are
back again with another interesting video on V/S topic. If we talk about web development, we are all
aware of JavaScript�s recognition in the current industry and how widely it is being
used right? But when it comes to larger and complex applications, working with Javascript
would not be a good choice. And because it lacks some of the features
and functionalities and due that most of the web developers felt a need of having something more versatile with advanced features
and better code structures, that is when typescript came into the picture.
And, this debate of choosing between Typescript and Javascript , has been a long
overdue. So, keeping that in mind, we will talk about the same, that is Javascript vs
Typescript. So guys before we proceed forward, do subscribe
to Intellipaat's YouTube channel so that you never miss out on our any upcoming videos.
So, let's have a look at the agenda for this video. First and foremost, we will discuss
the Basics of Javascript and Typescript. After that how it came into existence then
Features of Typescript and Javascript Why Typescript is in demand currently
which is better to use in terms of compilation, prototyping and data binding.
At last, what would be your expected salary if you are opting for either of them.
We will also have a short quiz at the end to recap what all you have learned from this
video. So don't forget to put down your answers in the comment section below to know if you
are correct. And if you are looking for courses in the
trending technologies, do visit intellipaat.com. Alright guys so now without any further delays,
let's get started. So guys, now let us get into the introductory
level of knowledge about Typescript and Javascript and further we�ll go into detail. What is JavaScript:
Javascript is a popular programming language of web technology. It�s a scripting language
by using which you can create interactive web pages.
Javascript is majorly used for creating client-side dynamic pages and the programs that we write
in JavaScript are known as Scripts. Scripts can be written in HTML(i.e. Notepad,
Notepad++) pages, and you can save the source file with .html or .js extension. The programs
gets executed as the html page gets loaded. Scripts are executed as plaintext and you
don�t need any special preparation or compilation to run these programs.
You can run Javascript with other technologies such as XML, REST, APIs etc.
Javascript was developed for large complex applications i.e. It�s only applicable for
the small applications which consists of a few lines of code. What is TypeScript:
Typescript is an object-oriented programming language and it is open source.
Typescript is a combination of Javascript and some additional features like static typing,
classes, and interface. It contains types. That�s why people also refer this as modern
generation JavaScript development language.There�s a concept called �Typing� in this. Using
which you can create types, declare types and you must ensure that the type checking
happens during the type compilation process. You can also say that Typescript is a superset
of Javascript. TypeScript contains a few syntax features that you can put into Javascript
code as well but not necessarily. If you are writing a Javascript, it�s a valid Typescript,
if you want, you can add a little bit of typescript features and still it�ll be a valid Typescript.
Even if you are adding complete typescript features, still it�ll be valid in Typescript.
But, you can�t directly run the TypeScript on the browsers, as it needs a compiler to
compile and generate in the javascript file. In this, the source is saved with �.ts�
extension. Now, I will move further to discuss about
another topic i.e. how did developers came up with the idea of TypeScript while having
JavaScript? 2. Typescript development over Javascript In the very beginning when JavaScript was
developed, people were using it just as the client side programming language. But, later
developers got to know that it can also be used as a server side programming language.
As people were using more and more javascript, it started getting heavier and more complex.
Because of that developers were not able to fulfill the requirement of object oriented
programming language in JavaScript. That�s how TypeScript came into the picture to bridge
the gap. 3. Why Typescript and Javascript Why Javascript:
Normally, JavaScript is considered as a design tool for small application which has a few
lines of codes i.e. small scripts. You can compile and run JavaScript in any
browser JavaScript also allows cross-compilation.
You can extend JavaScript for writing large apps Why TypeScript: TypeScript is a superset of Javascript as
I explained earlier. TypeScript supports JS API Documentation and
JS libraries as well. You can convert TypeScript Code into plain
JavaScript Code Typescript is optionally typed scripting language
that means you can write the source code as per the requirement if you want to add typing
with Javascript or complete typing, it's applicable in TypeScript.
TypeScript has object-oriented programming technique and better code structure as compared
to JavaScript. If you are using Typescript, then it�ll
also help you to extend the language beyond the standard decorators.
Now we�ll see what are the Pros and Cons of using TypeScript over Javascript: 4. Pros:
Biggest advantage of using TypeScript is it always highlights errors at compilation time
during the time of development, whereas if you use JavaScript, errors gets pointed out
at the runtime. You can run TypeScript on any browser or JavaScript
engine. TypeScript includes a feature that is strongly-typed
or supports static typing. And Static typing helps us for checking the type correctness
at compile time. But, This feature is not available in JavaScript.Typescript can be run on any browser or Javascript Engine. Typescript includes a feature that is strongly typed or support static typing. Static typing helps in checking the type correctness at compille time but this feature is noot available in javascript. Typescript also has a namespace concept by defining a module.
Additional benefit of using Typescript is it allows great tooling supports with IntelliSense
which provides active hints as the code is added.
In other words, you can say that TypeScript is nothing but JavaScript and some additional
features i.e. ES6 features. Sometimes, It may not be supported in your
target browser but TypeScript compiler can compile the .ts files into ES3,ES4 and ES5
as well. Frameworks like Angular2 also usage Typescript
as a programming language. Cons:
Usually TypeScript takes a longer time to compile the code as compared to Javascript.
It does not support abstract classes. If you run the TypeScript application in the
browser, a compilation step is needed to transform TypeScript into JavaScript. 5. Features of Typescript and Javascript
Let�s understand the features of Typescript and Javascript one by one. I will not go in
detailing as we have time constraints, but I�ll try to make it short and to-the-point. Feature of Javascript: Javascript is easy to understand and to begin
with. You can use Javascript for client side and
server side as well. Javascript is a dynamic language i.e. flexible
and powerful If you are using Javascript, then you are
free to do whatever you want with any object. It has strong Testing Workflow.
Javascript is a cross-platform language. Javascript is not supported in Framework. Feature of Typescript:
TypeScript can be used anywhere i.e. you can run the source code on any browser, devices
or in any OS(operating system). Remember, TypeScript is not specific to any Virtual-machine.
If you are using TypeScript, you can use existing JavaScript code, incorporate popular JavaScript
libraries. And you can also call from other JavaScript code asTypeScript supports JS libraries
TypeScript is superset of Javascript. So, whatever code you write in JavaScript gets
converted into TypeScript by changing the extension from .js to .ts.
TypeScript Code gets converted into Plain JavaScript Code as Browsers can't understand
the Typescript code. So,if the code is written in TypeScript then code gets compiled and
converted i.e. translated into JavaScript.And by the help of JavaScript code, browsers can
read and display the code. This whole process is known as Trans-piled. Now, let us take a quick look at some of the
key parameters to differentiate between these two: 7. Javascript vs Typescript 1. Compilation: In Typescript, error gets
highlighted during the development time i.e. compile time. But as Javascript is an interpreted
language, the code' error gets highlighted at runtime itself.
2. Execution: You can't directly run Typescript code on the browser. But, Javascript code
directly runs on the browser. 3. Prototyping: Typescript consists a feature
of prototyping whereas Javascript doesn't. 4. Annotation: As TypeScript is a typed language,
so developer should constantly specify the type of the variables, function parameters
and object properties in their code. Whereas, no Annotations is required for Javascript.
5. Advanced OOp features:Typescript supports classes, inheritance, interfaces, generics
and modules. Whereas, Javascript is a scripting language. Typescript considers number and
string as the interface whereas, Javascript consider it as objects.Typescript also gives
support for modules whereas Javascript does not. As we have quickly discussed about the parameters based on which we have made some differences Now let us move forward and discuss about parameters which has actually influences the differences in them. that is codes and syntaxes So now if you look at a screen out here there are two codes for multiplication in both javascript and typescript which actually influence the difference in them that is codes and synatxes So now if you look at a screen right here there are two codes for multiplication in both javascript and typescript. they look quite similar but in case of javascript you have to call the function in side the script only but in case of typescript you dont have to create the script so it might look a similar code over here but it when comes to longer implementation and longer application or i would say large application it actually becomes relevant when you dont add your objects or functions inside the script After knowing all the facts about them, you
must be wondering which one is most preferred or recommended to use by the developers. 9. Which is better Typescript or Javascript? Well it depends, if you are an experienced
developer and working on projects or applications which consists of relatively lesser lines
of codes, then you should definitely go with JavaScript. But, if you have knowledge and
expertise development team, then for applications which has complex and larger number of code,
Typescript is the most recommended here. 10. Finally, on aspects of salary you can
have a look if you are opting for any of these: Job Vacancy and Salary: According to Indeed.com, full-time Job vacancy
for Javascript developer is 27,775 and average salary ranges from $80,000 to $ 1,20,000 per
annum based on the experience and skill. Whereas, full-time Job vacancy for Typescript developer
is 3, 443 and the average salary varies from $90,000 to $1,25,000 per annum as per the
experience of candidate. Javascript was developed in 1995 and ever since developers
are using it and implementing new features in it time and again. Hence the job occupancy
for Javascript is higher and companies like Instagram, Airbnb and Codecademy and many
more uses Javascript. Launched in November 2012, Typescript is an
object-oriented language, so you can use most of the advanced oop features like modules,
interface, generic, and other features like static typing and a lot more which are not
supported in Javascript. That is the major reason why Frameworks like Angular 2 also
uses Typescript. In a nutshell, I�d like to add that, due
to JavaScript being an old language, majority of industries have used it and still using
it widely, that is one of the reasons why it is a go to programming language when it
comes to web development right? Typescript on the other hand, typescript is a newcomer
and just entered the market like 7 years ago? Right? But ever since it came into the picture,
it is giving a tough competition to most of the scripting languages out there, due to
its advanced features. Therefore, one can confidently say that demand
for Typescript will be more in the future as compared to Javascript. Companies like
Clever, Asana, Screen award and so on are using Typescript. Industry usage for Typescript
is growing rapidly day by day. So, guys we are heading towards the end of
the video. Finally, I would like to ask a Question based on Typescript and Javascript.
If you know the answer then write it in the comment section below. Quiz
From the options mentioned below, do you know which option fits for features of Typescript? Option 1: Typescript can be compiled to all
major versions of Javascript like Javascript ES3, ES5, ES6 and Javascript ES7.
Option 2: Typescript is the superset of JavaScript which provides typed nature to your code
Option 3: Typescript can be used for cross �browser development and is an open source
project as well. Option 4: All of the above.
Option 5: None of these. Solution: Option 4