Typescript
Basic video: https://www.youtube.com/watch?v=WBPrJSw7yQA. Video for react: https://www.youtube.com/watch?v=NjN00cM18Z4.
6 flashcards · Programming Languages · by lakesare
Declare a variable of type number.
const hi: number = 3;
Write 2 ways to declare an array of strings.
let marks: string[] = [80, 85, 75]; let marks: Array<string> = [80, 85, 75];
enum Color { red, green }; const rrr: Color = Color.green; console.log(rrr); What is the output?
=> 1. It was compiled into: "use strict"; var Color; (function (Color) { Color[Color["red"] = 0] = "red"; Color[Color["green"] = 1] = "green"; })(Color || (Color = {})); const rrr = Color.green; console.log({ rrr, aaa });
Define a type that can be either number or boolean.
let me: number | boolean; me = 20; me = true;
What does ? achieve?
It makes num2 optional. In Js: if you don't pass a variable it will be undefined. In Typescript: if you don't pass a variable, error will be raised!
Factor out type: