Function statements and functions expressions in javascript

Something Like that:
Function statements and functions expressions

What is Function statement
Fly will be work everywhere

For that you need to create first html code.

HTML

<p>Function statement =  <span id="demo"></span></p>

After that add this JS code.

JS

greet();
function greet(){
    document.getElementById("demo").innerHTML = 'Hi';
}

[codepen_embed height=”265″ theme_id=”0″ slug_hash=”JyWZvN” default_tab=”result” user=”pradeepanvi”]See the Pen Function statement in javascript by Pradeep Kumar (@pradeepanvi) on CodePen.[/codepen_embed]

Now you can see

Function statement = Hi

What is Function Expression
Fly work only after function

For that you need to create first html code.

HTML

<p>Function Expression =  <span id="demo"></span></p>

After that add this JS code.

JS

var agreet = function(){
    document.getElementById("demo").innerHTML = 'Hi';
}
agreet();

[codepen_embed height=”265″ theme_id=”0″ slug_hash=”vJxrwa” default_tab=”result” user=”pradeepanvi”]See the Pen Function Experssion in javascript by Pradeep Kumar (@pradeepanvi) on CodePen.[/codepen_embed]

Now you can see
Function Experssion = Hi

We can also Pass function expression into statement

For that you need to create first html code.

HTML

<p>Function Expression into statement =  <span id="demo"></span></p>

After that add this JS code.

JS

    function log(a){
        a();
    }
    log(function(){
        document.getElementById("demo").innerHTML = 'Hi';
    })

[codepen_embed height=”265″ theme_id=”0″ slug_hash=”gxmjOE” default_tab=”result” user=”pradeepanvi”]See the Pen Pass function expression into statement in javascript by Pradeep Kumar (@pradeepanvi) on CodePen.[/codepen_embed]

Now you can see
Function Expression into statement = Hi

Leave a Reply

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