javascript 2

4760 ワード


<script> function abs(){ var x; if(x>0){ return x; } else{ return -x; } } console.log(abs(-9));// NaN </script>

<script> function abs(x){ //var x; if(x>0){ return x; } else{ return -x; } } console.log(abs(-9));// 9 </script>

<script> function abs(){ //var x; if(x>0){ return x; } else{ return -x; } } console.log(abs(-9));// ReferenceError: x is not defined if(x>0){ </script>

<script> function abs(){ //var x; if(x>0){ return x; } else{ return -x; } } console.log(x=-9);// -9 </script>

<script> function abs(x){ //var x; if(x>0){ return x; } else{ return -x; } } console.log(x=-9);// -9 </script>
<script>

    function abs(x){

        //var x;

        if(x>0){

            return x;

        }

        else{

            return -x;

        }



    }

    abs(-9);

    console.log(x=-9);//  -9

    </script>