Day 8 : TypeScript
Basic Concepts in TypeScript:
Variable declaration :
- The default or traditional declaration of variable is :
var a : number = 10;
- The let and const are two new concepts in variable declaration.
- The let keyword is some what same as var keyword.
- The let keyword allows user to avoid some of "gotchas" that we use in JS.
- Now, you all wondering what is "gotchas"??
Gotchas are nothing but some what errors which we can avoid for better output. Consider a loop as an example :
//var keyword gives access to i outside loop.
//code:
for(var i=0;i<5;i++) {
console.log(i);
}
console.log(i);
//output:
0
1
2
3
4
5
//let keyword not gives access to i outside loop.
//code :
for(let i=0;i<5;i++) {
console.log(i);
}
console.log(i);
//output :
Error : Cannot found i
- So from above eg. we can say that, variables declared with let keyword cannot accessed outside block.
- The const keyword prevents the reassignments of variables.
Creating a class :
- In general, class is a blueprint of object.
- We can say that, class contains a group or collection of objects having common properties.
- Class contains or encapsulates data for objects.
- Syntax :
class class_name {
.......
//class scope
}
Creating a object :
- Object is a instance of a class.
- Object is a real-world and run-time entity.
- Object is a entity that have state(data) and behavior(functionality).
- Syntax :
var object_name = new class_name();
Import :
- For using or accessing a already written program or module we use import statement.
- Syntax :
import { export file_name } from "file path without extension"
- Eg :
Export :
Tsconfig file :
- The tsconfig.json file indicates the root directory of TypeScript.
- The tsconfig.json file specifies the root files as well as the compiler options for compiling a program.
- As we run tsc command for each .ts file for converting it into .js file. The tsconfig.json file converts the all .ts file into .js and make our work easy.
- For tsconfig.json file run following command on terminal :
- The above command automatically creates a tsconfig.json file.
- We can use a "outDir" for creating a new folder which having the .js files of our module, as i created in above image.
Thank You!!!
For more understanding watch below video :
JavaScript Day 1 : Day 1
JavaScript Day 2 Global Pollution : Day 2 Global
JavaScript Day 2 Undefined and Hoisting : Day 2 Undefined
JavaScript Day 3 : Day 3
JavaScript Day 4 : Day 4
JavaScript Day 5 : Day 5
JavaScript Day 6 : Day 6
TypeScript Day 7 : Day 7
Comments
Post a Comment