1.

What Is The Need For Typescript In Angular2?

Answer»

Understanding the need for TypeScript file in Angular2 applications : JavaScript rules in Web development. Its the most popular language for developing web application UI. For may application developers having exposure in languages like Java and C#, creating the front end of a Web application in JavaScript is a very cumbersome process. For EXAMPLE if the user wants to create a class Employee in JavaScript. There is no class keyword in JavaScript so the code will be as follows-

<html>
<head>
</head>
<BODY>
<SCRIPT>
function Employee()
{
this.name="";
this.ID="";
this.Validate=function()
{
alert("Validate");
}
}
</script>
</body>
</html>
Same can be written using TypeScript as follows-

class Employee
{
public name : string = "";
public id : string = "";
Validate()
{
alert("validate");
}
}

This Customer.ts will compile to the above JavaScript code.

So TypeScript provides the following advantages over JavaScript-

  • Structure the code- There were many different coding styles for JavaScript. This leads to unstructured code. With TypeScript we create structured code.
  • Use object-oriented programming paradigms and techniques- There is lack of object-oriented design paradigms and techniques in JavaScript. This is not the case in TypeScript. It makes use of Objected Oriented features like Polymorphism, Inheritance etc.
  • Standard Coding guidelines- There is no Type checking in JavaScript. The code style needs to be DEFINED. Hard to enforce style guide. TypeScript overcomes this issue with features like Code Analysis and Navigation, Documentation, Intellisense etc.

Understanding the need for TypeScript file in Angular2 applications : JavaScript rules in Web development. Its the most popular language for developing web application UI. For may application developers having exposure in languages like Java and C#, creating the front end of a Web application in JavaScript is a very cumbersome process. For example if the user wants to create a class Employee in JavaScript. There is no class keyword in JavaScript so the code will be as follows-

<html>
<head>
</head>
<body>
<script>
function Employee()
{
this.name="";
this.id="";
this.Validate=function()
{
alert("Validate");
}
}
</script>
</body>
</html>
Same can be written using TypeScript as follows-

class Employee
{
public name : string = "";
public id : string = "";
Validate()
{
alert("validate");
}
}

This Customer.ts will compile to the above JavaScript code.

So TypeScript provides the following advantages over JavaScript-



Discussion

No Comment Found