Functions in TypeScript | optional parameters, void, local variables, implicit returns #kody_az

Dərs haqqında

TypeScript-də funksiyalar JavaScript-dəki kimi işləyir, amma əlavə olaraq parametr və return tiplərini dəqiqləşdirməyə imkan verir. Parametrlərə string, number, boolean kimi tiplər yazmaq kodu daha təhlükəsiz edir və səhvləri erkən tutmağa kömək edir. Funksiyanın return tipi ya açıq yazılır, ya da TypeScript onu return ifadələrindən avtomatik çıxarır (infer). Optional parametr ? ilə göstərilir və göndərilməyəndə dəyəri adətən undefined olur. rest parametrlər (...args) çoxlu argument qəbul etmək üçün istifadə edilir və tuple-rest ilə “ən az 1 parametr” kimi qaydalar da qoya bilərsən. strict ayarları (xüsusən noImplicitAny, strictNullChecks) funksiya parametrləri və return dəyərlərində gizli problemləri “xəta” kimi göstərərək kod keyfiyyətini artırır.

====

In TypeScript, functions work the same way as in JavaScript, but you can also specify parameter and return types more precisely. Adding types like string, number, and boolean to parameters makes your code safer and helps catch mistakes early. A function’s return type can be written explicitly, or TypeScript can infer it automatically from the return statements. An optional parameter is marked with ?, and if it isn’t provided, its value is usually undefined. Rest parameters (...args) are used to accept multiple arguments, and with tuple-rest you can enforce rules like “at least one argument.” Strict settings (especially noImplicitAny and strictNullChecks) improve code quality by turning hidden issues in function parameters and return values into compile-time errors.

#kody_az #kodyaz #js #typescript #nodejs #es6 #ts #viral #viralcode #viralvideo #code #coder #azerbaycan #azerbaijan #baku #baki #programming #programmer #hazırlıq #hazirliq #kurs #kurslar #course #courses #online #onlinecourses

YouTube-da bax · KODY.AZ