Java vs Typescript Syntax

 Hi, the post is only related to the comparison between the basic syntax in Java & Typescript.

We may need a class and a main function in Java to print a text in the console unlike in Typescript.

Syntax Differences b/w Java & Typescript:



Classes:



Functions:



Variables inside a Class:



Variables inside a method:



Deep Dive into the Typescript:

Types:

When we try to return number instead of String for string type function, it throws error


Types can be customized with multiple return types.

Always throws error when we try to return value that is not defined


Not only primitive types but also values can be assigned as types.


It throws error if an undefined value is being returned



The main advantage of using types is not only it strict developer to give invalid values but also gives suggestions to use available values.

A function can be a multi-purpose action.
Maybe Method overloading is the solution for Java 🤕
What if a function can be used in 10 different ways, do we have to write 10 different methods??? 🤔
 
JAVA: 


But typescript has it's own way of handling it. Optional parameters! 🤩

TYPESCRIPT:


There are so many other features in typescript to code logically easiest and cleanest way compared to Java. Making use of 
all typescript features has it's own advantages.

Comments