Redefining functions in JS. Code example open

Redefining functions in JS. Code example

Functions have the ability to override behavior. The redefinition occurs by assigning an anonymous variable function that has the same name as the overridden function:

Consider an example:

    function display() {//create a function and call it display
        console.log("first text");//the function will output "first text" to the console
        display = function () {//let's name the variable as a function that we want to reassign
            console.log("second text");//let's reassign the value to the function
        }
    }

    display(); //first text
    display(); //second text
0

More

Leave a Reply

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

How many?: 22 + 22

lil-code© | 2022 - 2024
Go Top
Authorization
*
*
Registration
*
*
*
*
Password generation