function name(parameter) {
//함수본문
return //출력값
}
function getRectangleArea(width, height) {
let rectangleArea = width * height;
return rectangleArea
}
let getRectangleArea = function(width, height) {
let rectangleArea = width * height;
return rectangleArea
}
let getRectangleArea = (width, height) => {
let rectangleArea = width * height;
return rectangleArea
}
*함수 본문이 한줄일 경우 중괄호와 return 생략 가능
let getRectangleArea = (width, height) => width * height;
sayHello("Somin");
// hello, Somin.
function sayHello(name) {
console.log( `hello, ${name}.`);
}
sayHello("Somin");
// hello, Somin.
sayHello("Somin");
// Error : sayHello is not defined
let sayHello = function (name) {
console.log( `hello, ${name}.`);
}
sayHello("Somin");
// hello, Somin.
let age = 26;
if (age > 18){
function sayWelcome() {
alert("Welcome");
}
}
sayWelcome(); // Error
let age = 26;
let sayWelcome
if (age > 18){
sayWelcome = function() {
alert("Welcome");
}
}
sayWelcome(); // "Welcome"