TypeScriptで関数(function)を定義するサンプル

2021年11月12日

環境
Windows 10 64 bit
TypeScript 4.4.4
書式
function 関数名(変数名:データの型):void{処理コード}
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
/*関数の定義*/
function funA(name: string): void {
console.log("study " + name + "smart");
}
let target: string = "skill become ";
//関数を呼び出す
funA(target);
/*関数の定義*/ function funA(name: string): void { console.log("study " + name + "smart"); } let target: string = "skill become "; //関数を呼び出す funA(target);
/*関数の定義*/
function funA(name: string): void {
    console.log("study " + name + "smart");
}
let target: string = "skill become ";
//関数を呼び出す
funA(target);

実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
>tsc
>ts-node arkgame.js
study skill become smart
>tsc >ts-node arkgame.js study skill become smart
>tsc
>ts-node arkgame.js
study skill become smart

 

TypeScript

Posted by arkgame