Function in JS / ES6

Function in JS / ES6

  • Default Function

                        <script>

                                    function Demo()

                                    {

                                                alert(“I am a Default Function”);

                                    }

                                    Demo();

                        </script>

  • Parametrized Function

                        <script>

                                    function Demo(type)

                                    {

                                                document.write(“I am a “+ type + ” Function”);

                                    }

                                    Demo(“parameterized”);

                        </script>

  • Default Parameter Value

                        <script>

                                    function Demo(type=”default parameter”)

                                    {

                                                document.write(“I am a “+ type + ” Function”);

                                    }

                                    Demo();

                        </script>

  • Anonyms Function

                        <script>

                                    let x=function()

                                    {

                                                console.log(“I am an Anonmys Function”);

                                    }

                                    x();

                        </script>

  • Arrow Function

                        <script>

                                    let x=()=> console.log(“I am an Arrow Function”);

                                    x();

                        </script>

Or

                        <script>

                                    let x=()=> “I am an Arrow Function1”;

                                    console.log(x());

                        </script>

Or

                        <script>

                        var add = (x,y)=>x+y;

                        console.log(add(10,20));

                        </script>

Or

<script>

      const isEven = (n1) => {

      if(n1%2 == 0)

         return true;

      else

         return false;

   }

   console.log(isEven(10));

</script>

One thought on “Function in JS / ES6

Post Your Comments & Reviews

Your email address will not be published. Required fields are marked *

*

*