Summary
Congratulations!
You've taken a small step for a person but a giant leap for your successful career! You've successfully completed the beginner course on TypeScript, and that's commendable. If you've tackled all the tasks and studied the theory, you're doing great! But if you skipped chapters just to get the certificate, well, that's your problem.
Let's summarize the entire beginner course, what TypeScript is, and why it's essential. We'll revisit the basic syntax, TypeScript's advantages, and much more.
Overall
TypeScript is a general purpose programming language that serves as a superset of JavaScript. TypeScript stands out with its static typing, error highlighting during the coding phase, object-oriented programming features, and many other improvements compared to JavaScript.
TypeScript is beloved and widely used. It's the go-to choice for front-end development in many prominent companies and is a key component in various popular frameworks. The simplest example is Angular.
Syntax
To display information in the console, we use the following syntax:
javascriptconsole.log("Text we want to output");
If we want to declare a variable without any type, we can use the following syntax:
javascriptlet name = value;
Typed variable:
typescriptlet name: type = value;
One-line comment:
javascript// commented fragment
Multi-line comment:
javascript912/* multi-linefragment */
Conditional Statements
Syntax of the if
statement:
javascript9123if (condition) {// code to be executed if the condition is true}
condition
must have a boolean
type!
if-else
statement:
javascript9912345678910if (first_condition) {// code block if the first condition is true} else if (second_condition) {/* A block of code that will executeif the first condition is falseand the second condition is true. */} else {/* A block of code that will executeif all previous conditions are false.}
Switch-case:
javascript9912345678910111213switch (expression) {case value1:// Code to be execute if expression equals value1break;case value2:// Code to execute if expresson equals value2break;// Additional cases...default:/* Code to execute if none of the casesmatch the expression}
Arrays
Declaring array:
javascriptlet name[]: type[] = [element1, elememt2, ... , elementN];
Zero-based indexing:
javascript[0, 1, 2, ..., n];
It means that the first element in the array will have an index 0, the second element will have an index 1, and so on.
You can get the element from the array using it's index:
javascriptvar element = array[index];
You can also modify the array's elements using their indexes:
javascriptarray[index] = value;
You can explore array methods in this chapter: Working with Array Elements
Loops
while-loop
syntax:
javascript91234while (condition) {// The code that the loop will execute// while the condition is `true`}
The keyword break
is used to immediately stop the execution of a loop.
do-while
loop syntax:
javascript912345do {// The code that the loop will execute// while the condition is `true`} while (condition)
The do-while
loop will execute at least once.
for
loop syntax:
javascript9123for (initialization; condition; increment/decrement) {// Code to be executed in each iteration}
Functions
Functions syntax:
javascript9123function name(parameter: type, optionalParameter?: type, defaultParameter: type = value) : returnType {// reusable code block}
How to call a function?
javascriptfunctionName(parameters);
These are the basic concepts and syntax you've covered in this course.
From this point on, you have a foundation in TypeScript, and you can write simple programs and functions. In future courses, you will learn more advanced topics, such as object-oriented programming, classes, objects, anonymous functions, and much more.
Now, I want to congratulate you once again and wish you a well-deserved rest. You've done great!
Bedankt voor je feedback!
Vraag AI
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.