Skip to content

Udemy/Ts/section2/15 #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function add(n1, n2, showResult, phrase) {
if (showResult) {
console.log(n1 + n2);
}
else {
return n1 + n2;
}
}
var number1 = 5;
var number2 = 2.8;
var printResult = true;
var resultPhrase = 'Result is: ';
add(number1, number2, printResult, resultPhrase);
4 changes: 3 additions & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
function add(n1: number, n2: number, showResult: boolean, phrase: string) {
const result = n1 + n2; //result는 number라고 추론을 한다.
if (showResult) {
console.log(n1 + n2);
console.log(result + phrase);
} else {
return n1 + n2;
}
Expand All @@ -10,5 +11,6 @@ const number1 = 5;
const number2 = 2.8;
const printResult = true;
const resultPhrase = 'Result is: ';
// resultPhrase = 0; //error -> 타입 추론으로 resultPhrase는 string이다. 따라 0이라는 number타입을 할당할 수 없다.

add(number1, number2, printResult, resultPhrase);