DEV Community

Softhunt
Softhunt

Posted on • Updated on

 

TypeScript Vs JavaScript: What is the Difference?

In this article, we will see the comparison of typescript vs JavaScript with advantages and disadvantages.

What is JavaScript

JavaScript is the most widely used HTML and Web programming language. JavaScript is a lightweight, cross-platform object-based programming language. It's used to make dynamic client-side pages. Scripts are programs written in the JavaScript programming language. The scripts are embedded in HTML pages and run in the background when the page loads. It is delivered and performed as plain text, and no extra preparation or compilation is required to run it.

History of JavaScript

Brendan Eich, a programmer at Netscape Communications Corporation, created JavaScript. It was first released in September 1995 under the name Mocha. However, it was renamed JavaScript to reflect Netscape's use of Java within its browser as it gained prominence as the greatest scripting language. Netscape submitted JavaScript to ECMA in November 1996. (European Computer Manufacturers Association). ECMAScript 2019, which was released in June 2019, is the most recent version of JavaScript.

What is TypeScript

TypeScript is an object-oriented programming language that is free and open-source. It's a superset of JavaScript that's highly typed and compiles to ordinary JavaScript. Microsoft created and maintains TypeScript under the Apache 2 license. It is not a browser-based application. To compile and produce a JavaScript file, you'll need a compiler. The ".ts" suffix refers to the TypeScript source file. By renaming any valid ".js" file to ".ts" we may utilize it. TypeScript is an ES6-based version of JavaScript with a few more capabilities.

History of TypeScript

The typescript was created by Anders Hejlsberg. It was originally made available to the general public on October 1, 2012. The latest version of TypeScript 0.9 was published in 2013 after two years of internal development at Microsoft. TypeScript 4.5.4, which was published on 13 December 2021, is the most recent version.

TypeScript Vs JavaScript

Code Example of JavaScript:

let var = "Hello Welcome to Softhunt.net";
var = 15;
console.log(var); 
Enter fullscreen mode Exit fullscreen mode

Code Example of TypeScript:

let var: string = "Hello Welcome to Softhunt.net";
var = 15;
console.log(var);
Enter fullscreen mode Exit fullscreen mode

Advantages of TypeScript over JavaScript

  • During development, TypeScript always indicates faults at compilation time, whereas JavaScript reveals issues at runtime.
  • TypeScript allows highly typed or static typing, whereas this is not in JavaScript.
  • Any browser or JavaScript engine can execute TypeScript.
  • Great tooling supports IntelliSense which provides active hints as the code is added.
  • It has a namespace concept by defining a module.

The disadvantage of TypeScript over JavaScript

  • The compilation of TypeScript code takes a lengthy time.
  • Abstract classes are not supported by TypeScript.
  • If we launch the TypeScript program in the browser, we'll need to compile it first to convert it to JavaScript.

Conclusion

When comparing the pros and downsides of typescript vs javascript, it can be concluded that both technologies have advantages and disadvantages. Although JavaScript is not a complete coding language, it is used in conjunction with HTML to improve the quality of online pages. In addition, JavaScript is used by thousands of professional developers.
TypeScript, on the other hand, is the language of choice for developers who want to write clean, elegant, concise, and readable code. Not to mention TypeScript's benefits in terms of live error checking and static typing.
Suggested Articles:

  1. ES5 vs ES6 ( With example code )
  2. ES6 Syntax and Feature Overview
  3. Top 10 ES6 features by example

Top comments (2)

Collapse
 
silviuvladut profile image
Silviu Vladut

Where's the TypeScript from the 2nd example of code?
For me seems JavaScript, not TS

Collapse
 
softhunt profile image
Softhunt

I will update it thankyou for pointing it out.

typescript

11 Tips That Make You a Better Typescript Programmer

1 Think in {Set}

Type is an everyday concept to programmers, but it’s surprisingly difficult to define it succinctly. I find it helpful to use Set as a conceptual model instead.

#2 Understand declared type and narrowed type

One extremely powerful typescript feature is automatic type narrowing based on control flow. This means a variable has two types associated with it at any specific point of code location: a declaration type and a narrowed type.

#3 Use discriminated union instead of optional fields

...

Read the whole post now!