0
0
Typescriptprogramming~5 mins

How TypeScript compiles to JavaScript - Quick Revision & Summary

Choose your learning style9 modes available
Recall & Review
beginner
What is the main purpose of compiling TypeScript to JavaScript?
TypeScript code is converted into JavaScript because browsers and Node.js can only run JavaScript. The compiler removes TypeScript-specific features like types and outputs plain JavaScript.
Click to reveal answer
beginner
What file extension does TypeScript use and what does it produce after compilation?
TypeScript files use the .ts extension. After compilation, they produce JavaScript files with the .js extension.
Click to reveal answer
beginner
How does the TypeScript compiler handle type annotations during compilation?
Type annotations are used only during development for checking errors. The compiler removes all type annotations in the output JavaScript because JavaScript does not support types.
Click to reveal answer
beginner
What command is commonly used to compile a TypeScript file named app.ts?
The command is tsc app.ts. This runs the TypeScript compiler and creates a JavaScript file named app.js.
Click to reveal answer
intermediate
Can TypeScript compile to different versions of JavaScript? How?
Yes. You can set the target JavaScript version (like ES5, ES6) in the tsconfig.json file or with the --target option. This controls the JavaScript features used in the output.
Click to reveal answer
What does the TypeScript compiler remove when converting to JavaScript?
AVariable names
BAll functions
CComments only
DType annotations and interfaces
Which file extension is generated after compiling a TypeScript file?
A.ts
B.tsx
C.js
D.json
Which command compiles a TypeScript file named main.ts?
Anode main.ts
Btsc main.ts
Cnpm main.ts
Dcompile main.ts
Why do we compile TypeScript to JavaScript?
ABecause JavaScript cannot run TypeScript directly
BTo add more types to the code
CTo make the code run faster
DTo convert JavaScript to TypeScript
How can you control the JavaScript version output by the TypeScript compiler?
AUsing the <code>--target</code> option or <code>tsconfig.json</code>
BBy renaming the output file
CBy changing the file extension to .js
DBy running JavaScript code first
Explain in your own words why TypeScript code needs to be compiled to JavaScript before running in a browser.
Think about what browsers can run and what TypeScript adds.
You got /4 concepts.
    Describe the role of the TypeScript compiler and what happens to type annotations during compilation.
    Focus on what the compiler does with types and the output.
    You got /4 concepts.