LeetCode λ¬Έμ νλ€κ° μλ₯΄λ₯΄λ₯΄λ₯΄...π€
ν¨μμ λν΄ μ΄λκΉμ§ μκ³ μλ...
ν¨μκ³΅λΆ λ€μνκΈ°.. μ€λλ w3shoolμ μλκ³ΌπΆ
μ€λλ°€μ μμ¬λΆλ¦¬μ§ λ§κ³ w3sλ§ νμ€νκ² μ 리νλ €κ³ νλ€.
function ν¨μμ΄λ¦ () {}
ν¨μ μ΄λ¦μλ λ¬Έμ, μ«μ, _ κ·Έλ¦¬κ³ $λ‘ λͺ λͺ κ°λ₯ (like λ³μλͺ )
( )μμλ ','λ‘ κ΅¬λΆνλ 맀κ°λ³μ(parameter)κ° ν¬ν¨λ μ μλ€.
{ }μμλ ν¨μμ μν΄ μ€νλ μ½λκ° λ€μ΄κ°λ€.
Function arguments are the values received by the function when it is invoked. μΈμλ ν¨μκ° νΈμΆλ λ λ°λ κ°μ΄λ€.
Inside the function, the arguments (the parameters) behave as local variables.ν¨μ λ΄μμ μΈμ (λ§€κ° λ³μ)λ μ§μ λ³μλ‘ μλνλ€.
The code inside the function will execute when "something" invokes (calls) the function. ν¨μ λ΄λΆμ μ½λλ μ΄λ€ν¨μλ₯Ό νΈμΆ ν λ μ€νλλ€.
//ν¨μλ₯Ό νΈμΆνκ³ λ°ν κ°μ xμ λ€μ λ°νλλ€.
const x = myFunction(4, 3);
document.getElementById("demo").innerHTML = x;
function myFunction(a, b) {
return a * b;
}
function toCelsius(f) {
return (5/9) * (f-32);
}
document.getElementById("demo").innerHTML = toCelsius;
//function toCelsius(f) { return (5/9) * (f-32); }
Functions can be used the same way as you use variables, in all types of formulas, assignments, and calculations.ν¨μλ λͺ¨λ μ νμ 곡μ, ν λΉ λ° κ³μ°μμ λ³μλ₯Ό μ¬μ©νλ κ²κ³Ό λμΌν λ°©μμΌλ‘ μ¬μ©ν μ μλ€.
= λ³μλ₯Ό μ¬μ©ν λμ κ°μ΄ ν¨μλ₯Ό λ³μμ ν λΉν ν νΈμΆν μ μλ€.
ν¨μμ λ°ν κ°μ μ μ₯νκΈ° μν΄ λ³μλ₯Ό μ¬μ©νλ λμ :
const x = toCelsius(77); const text = "The temperature is " + x + " Celsius";
ν¨μλ₯Ό λ³μ κ°μΌλ‘ μ§μ μ¬μ©ν μ μλ€.
var text = "The temperature is " + toCelsius(77) + " Celsius";