๐Ÿฆœ Computer Language/JavaScript

[JavaScript] ํ•จ์ˆ˜

ํ•จ์ˆ˜ํ‘œํ˜„์‹

console.log(hello()); // Error

let hello = function(){
	return "Hello, World!"
};

console.log(hello()); // Hello, World!

 

 

ํ•จ์ˆ˜์„ ์–ธ์‹

console.log(hello()); // Hello, World! -> ๊ฐ€๋Šฅ

function hello() {
	return "Hello, World!"
}

console.log(hello()); // Hello, World!

 

ํ˜ธ์ด์ŠคํŒ…: ํ•จ์ˆ˜์„ ์–ธ์‹์œผ๋กœ ๋งŒ๋“ค์–ด์ง„ ํ•จ์ˆ˜๋“ค์€ ํ”„๋กœ๊ทธ๋žจ ์‹œ์ž‘ ์ „ ์ฝ”๋“œ์˜ ์ตœ์ƒ๋‹จ์œผ๋กœ ๋Œ์–ด์˜ฌ๋ฆฌ๊ธฐ ๊ฐ€๋Šฅ 

But, ํ•จ์ˆ˜ํ‘œํ˜„์‹์œผ๋กœ ๋งŒ๋“ค์–ด์ง„ ํ•จ์ˆ˜๋Š” ๋ณ€์ˆ˜์— ํ• ๋‹น ๋œ ํ›„์— ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

 

ํ™”์‚ดํ‘œํ•จ์ˆ˜

let hello = () => "Hello World!"

let add = (x, y) => {
	let result = x + y;
    return result;
};