1. Learning Type Script: Hello World
Introduction: Typescripts describe the shape and behavior of your code and what value will be when we run our program.
As already we are familiar with javascript we know the below code
const myvar= "Hello World!";
myvar.toLowerCase()
The above code will give you result with all lower case right?
Now check the below code
const myvar= "Hello World!";
//calling myvar
myvar();
What do you think about the above code? Is it will run correctly?
It will through an error like TypeError: myvar is not a function right?
So it would be great if we can avoid this type of mistake
So we can come to TypeScripts
TypeScript can catch bugs when we make mistakes in our code. That's great, but TypeScript can also prevent us from making those mistakes in the first place
We've been talking about type-checking, but we haven't yet used our type-checker. Let's get
acquainted with our new friend tsc , the TypeScript compiler. First, we'll need to grab it via npm.
Before running the below command pls check whether your node.js is installed or not.
npm install -g typescript
Now can start our first typescript program.
console.log("Hello world!");