Search code examples
javascriptnode.jscomputer-scienceobject-oriented-analysis

overloading vs overriding in javascript


In a recent JavaScript interview I was asked about overloading vs overriding. I know this is a concept in Java. But is there something similar in JavaScript, and if so what would be code examples? My understanding is that overloading isn't common in javascript. Why would you need to use "overloading" in JS?

OverRiding is a bit clearer to me - an example of over riding would be in subclassing where you are inheriting from a super class but over riding some methods/properties to create unique ones for a sub class.


Solution

  • JavaScript does not support overloading.

    JavaScript supports overriding, so if you define two functions with the same name, the last one defined will override the previously defined version and every time a call will be made to the function, the last defined one will get executed.

    more read here http://blog.mastykarz.nl/overloading-functions-javascript/