Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ まとめ | 関数
TypeScript入門

bookまとめ

メニューを表示するにはスワイプしてください

おめでとうございます!

あなたは小さな一歩を踏み出しましたが、キャリア成功への大きな飛躍となりました。 TypeScriptの初心者コースを無事に修了されました。これは称賛に値します。すべての課題に取り組み、理論を学習した場合、素晴らしい進歩です。 もし証明書を得るためだけに章を飛ばした場合、それはあなた自身の問題です。

この初心者コース全体、TypeScriptとは何か、そしてなぜ重要なのかをまとめます。基本構文、TypeScriptの利点などを再確認します。

概要

TypeScriptは汎用プログラミング言語であり、JavaScriptのスーパーセットとして機能します。TypeScriptは、静的型付け、コーディング中のエラーのハイライトオブジェクト指向プログラミングの機能、その他多くのJavaScriptに対する改良点で際立っています。

TypeScriptは多くの開発者に支持され、広く利用されています。多くの有名企業でフロントエンド開発の標準となっており、さまざまな人気フレームワークの主要な要素です。最も簡単な例はAngularです。

構文

コンソールに情報を表示するには、次の構文を使用します。

console.log("Text we want to output");

型を指定せずに変数を宣言したい場合、次の構文を使用します:

let name = value;

型付き変数:

let name: type = value;

1行コメント:

// commented fragment

複数行コメント:

/* multi-line 
fragment */

条件文

if 文の構文:

if (condition) {
    // code to be executed if the condition is true
}

conditionboolean 型である必要があります。

if-else 文:

if (first_condition) {
    // code block if the first condition is true
} else if (second_condition) {
    /* A block of code that will execute
       if the first condition is false
       and the second condition is true. */
} else {
    /* A block of code that will execute 
       if all previous conditions are false.
}

スイッチケース:

switch (expression) {
    case value1:
        // Code to be execute if expression equals value1
        break;
    case value2:
        // Code to execute if expresson equals value2
        break;
    // Additional cases...

    default:
        /* Code to execute if none of the cases 
match the expression
}

配列

配列の宣言:

let name[]: type[] = [element1, elememt2, ... , elementN];

ゼロベースのインデックス:

[0, 1, 2, ..., n];

これは、配列の最初の要素がインデックス0、2番目の要素がインデックス1となることを意味します。

配列から要素をインデックスで取得可能:

var element = array[index];

配列の要素はインデックスを使って変更可能:

array[index] = value;

この章では配列メソッドについても確認可能:配列要素の操作

ループ

while-loopループの構文:

while (condition) {
    // The code that the loop will execute 
    // while the condition is `true`
}

キーワード break は、ループの実行を直ちに停止するために使用。

do-while ループの構文:

do {
     // The code that the loop will execute 
    // while the condition is `true`
} while (condition)

do-while ループは少なくとも1回は実行。

for ループの構文:

for (initialization; condition; increment/decrement) {
    // Code to be executed in each iteration
}

関数

関数の構文:

function name(parameter: type, optionalParameter?: type, defaultParameter: type = value) : returnType {
    // reusable code block
}

関数の呼び出し方法

functionName(parameters);

このコースで学習した基本的な概念と構文

これでTypeScriptの基礎が身につき、簡単なプログラムや関数を書くことが可能。 今後のコースでは、オブジェクト指向プログラミング、クラス、オブジェクト、無名関数など、より高度なトピックを学習予定。

ここまでの努力に改めて敬意を表し、ゆっくり休んでください。素晴らしい成果。

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 5.  7

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 5.  7
some-alt