First Class Functions in javascript

Something Like that:
First Class Functions

What is First Class Functions
Everything you can do with other types you can do with functions.
(Assign them to variable, pass them around, create them on the fly)

For that you need to create first html code.

HTML

<p>Greet =  <span id="demo"></span></p>
<p>Greet Data =  <span id="demo2"></span></p>
<p>Greet Lang =  <span id="demo3"></span></p>

After that add this JS code.

JS

function greet(){
    document.getElementById("demo2").innerHTML = 'Hi';
}
greet.lang = 'en';
document.getElementById("demo1").innerHTML = greet;
document.getElementById("demo3").innerHTML = greet.lang;

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

Now you can see

Greet = function greet(){ document.getElementById(“demo2”).innerHTML = ‘Hi’; }
Greet Data =
Greet Lang = en

Leave a Reply

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