JS

[JS] 자바스크립트 return문

져니져니95 2021. 3. 29. 16:25

2020.03.24(수)

블록체인 기반 핀테크 및 응용 SW 개발자 양성과정 아홉째날

 

자바스크립트 return문

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script type="text/javascript">
        function sum(a,b,c){
            return a+b+c          
        }
        /*데이터타입이 있어야지만 변수에 담겨질 수 있다.*/
        a = sum(3,4,5);
        console.log(a);
    </script>
</head>
<body>
    
</body>
</html>

sum(a,b,c)를 a+b+c 로 값을 변환

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script type="text/javascript">
    function box(width,height){
        return width*height;
    }
    box1 = box(10,10);
    box2 = box(9,9);
    box3 = box(8,8);
    box4 = box(7,7);
    box5 = box(6,6);
    box6 = box(5,5);
    box7 = box(4,4);
    box8 = box(3,3);
    box9 = box(2,2);
    box10 = box(1,1);

    console.log(box1);
    console.log(box2);
    console.log(box3);
    console.log(box4);
    console.log(box5);
    console.log(box6);
    console.log(box7);
    console.log(box8);
    console.log(box9);
    console.log(box10);

    </script>
</head>
<body>
    
</body>
</html>

box(width,height)를 width*height값으로 변환