I've started to write code in TypeScript for 3 days. I have completed all my class designs but at this point I'm writing the main function. Everything is nice but somebody have to run the Main() function. I do this with this way;
I'm just curious about that is there any method which is not triggered by me ? or How do you handle your Main() methods when typing your code in TypeScript?
Many programming languages require a special user-written function that marks the begin of the execution. For example, in C this function must always have the name main() . In JavaScript, however, such a function is not required.
Types of Functions in TypeScript: There are two types of functions in TypeScript: Named Function. Anonymous Function.
Number , String , Boolean , Symbol and Object ❌ Don't ever use the types Number , String , Boolean , Symbol , or Object These types refer to non-primitive boxed objects that are almost never used appropriately in JavaScript code.
What does ?: mean in TypeScript? Using a question mark followed by a colon ( ?: ) means a property is optional. That said, a property can either have a value based on the type defined or its value can be undefined .
Unlike class-based languages, JavaScript
does not require a main
method.
Since TypeScript is a super-set of JavaScript
, all JavaScript code is also valid TypeScript, and therefore doesn't need a main.
So, you can call your Object (JavaScript) or Class (TypeScript) anything you'd like -- Main
, DoThis
or even ServeMeADrink
and all are equally valid and can be invoked by calling, just as you've done.
They can also be invoked by:
data-main
attribute used by some MVC/JavaScript systems.TypeScript, as JavaScript, doesn't have a main function. The code is executed from top to bottom, so you can just create the function and call it at the end of the main file, after the imports.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With