Refer to this to know what TS is able to compile: https://kangax.github.io/compat-table/es6/

“let” and “const”

Screenshot 2022-10-24 at 12.26.36 AM.png

This is fine, but what about the if statements:

Screenshot 2022-10-24 at 12.29.02 AM.png

Here, this will give error in TS but not in JS. So, if I compile and check browser:

Screenshot 2022-10-24 at 12.29.27 AM.png

You can see it is working fine. “let” fixes this. So, similarly if I do this using let:

Screenshot 2022-10-24 at 12.32.18 AM.png

Screenshot 2022-10-24 at 12.32.27 AM.png

Here, you can see we got the error in the browser instead of the output.

This will give error in both TS and JS and it won’t work. So, it is a good practice to use let instead of var.

Now, let is doing this because it uses something called as a block scope which means it has its availability only inside of {}.

Arrow Functions

Screenshot 2022-10-24 at 12.42.52 AM.png

Arrow functions save a lot of time and are very useful.

Default Function Parameters