ν•¨μˆ˜

0

javascript

λͺ©λ‘ 보기
2/34
post-thumbnail
post-custom-banner

πŸ“ν•¨μˆ˜

μž…λ ₯을 λ°›μ•„ 좜λ ₯을 ν•˜λŠ” ν•˜λ‚˜μ˜ μž‘μ€ κΈ°λŠ₯ λ‹¨μœ„μ΄λ‹€.

πŸ“Œ ν•¨μˆ˜ μ„ μ–Έ 방법 1

function myFunction(input){
    //μ»΄ν“¨ν„°μ—κ²Œ μ‹œν‚¬μΌ
}

πŸ“Œ ν•¨μˆ˜ μ„ μ–Έ 방법 2

let myFunction = function(input){ //input은 λ§€κ°œλ³€μˆ˜ 
    //μ»΄ν“¨ν„°μ—κ²Œμ‹œν‚¬μΌ
}

ν•¨μˆ˜ 예제λ₯Ό ν’€λ©΄μ„œ ν•¨μˆ˜λ₯Ό μ΅ν˜€ λ΄…μ‹œλ‹€.

πŸ‘ŒπŸ» μ§‘κ°€λŠ”λ° κ±Έλ¦¬λŠ” μ‹œκ°„μ„ κ΅¬ν•˜λŠ” ν•¨μˆ˜μ‹μ΄λ‹€.

let timeToGoHome = function(speed, distance){
	let time = distance / speed;
    return time;
 }

πŸ‘ŒπŸ» ν•¨μˆ˜λ₯Ό 좜λ ₯ν• λ•ŒλŠ” μ΄λ ‡κ²Œ !

timeToGoHome (10, 200)

✌🏻 κ°’

20

πŸ‘ŒπŸ» μ›μ˜ 넓이λ₯Ό κ΅¬ν•˜λŠ” ν•¨μˆ˜

function getAreaOfCircle(r){
    let pi = 3.141592;
    let areaOfCircle = pi* r * r ;
	return areaOfCircle; // 리턴을 ν•΄μ€˜μ•Ό 값이 좜λ ₯됨
}

πŸ‘ŒπŸ»ν•¨μˆ˜λ₯Ό 좜λ ₯할땐 μ΄λ ‡κ²Œ !

getAreaOfCircle(5)

βœŒπŸ»κ°’

78.5398

πŸ’• μ°Έκ³ ν•˜κ³  κ°€λ©΄ 쒋을 팁

  1. Number(anything)
    -> λ¬Έμžμ—΄(string)을 number νƒ€μž…μœΌλ‘œ λ¦¬ν„΄ν•©λ‹ˆλ‹€.

  2. String(anything)
    -> numberνƒ€μž…μ„ λ¬Έμžμ—΄ (string) νƒ€μž…μœΌλ‘œ λ¦¬ν„΄ν•©λ‹ˆλ‹€.
    ->anything μ—λŠ” number, string, boolean νƒ€μž…λ§Œ μž…λ ₯λ©λ‹ˆλ‹€. μ•„λ‹κ²½μš° NaN좜λ ₯

profile
πŸ‘©πŸ»β€πŸ’»ν•­μƒλ°œμ „ν•˜μž πŸ”₯
post-custom-banner

0개의 λŒ“κΈ€