Skip to main content

Posts

Showing posts with the label function overloading in JavaScript

Understanding JavaScript Inheritance with Example [How To]

How to “ Achieve Inheritance ”in JavaScript? In the JavaScript , we can implement the Inheritance using the some alternative ways and we can’t define a class keyword but we create a Constructor function and using new keyword achieves it.   The some Alternative ways As, 1.       Pseudo classical Inheritance 2.       Prototype Inheritance Pseudo  classical   Inheritance   is the most popular way. In this way, create a constructor function using the new operator and add the members function with the help for constructor function prototype. The  Prototype  based  programming is a technique of object oriented programming. In this mechanism we can reuse the exiting objects as prototypes.  The prototype inheritance also known as prototypal,  classless or instance based inheritances. Example as, // Create a helper function. if ( typeof Object .create !== 'functio...

What is function overloading in JavaScript?

There is no real function overloading in JavaScript and it allows to pass any number of parameters of any type. You have to check inside the function how many arguments have been passed and what is the type arguments using  typeof . How to create function overloading in JavaScript? The example for function overloading not supporting in JavaScript as give below. function   sum(a, b) {     alert(a + b); } function   sum(c) {     alert(c); } sum(3); //The output is 3. sum(2, 4); //The output is 2. In the JavaScript, when we write more than one functions with same name that time JavaScript consider the last define function and override the previous functions. You can see the above example output for the same. We can achieve using the several different techniques as give below You can check the declared argument name value is undefined. We can check the total arguments with  arguments.length...