Monday, July 28, 2014

Javascript Return False

What the hell is "Return False" and what it do

Many times in our code we have used Return false and also somewhere in the same code we have use the event.preventDefault and event.stopPropogation.

But did we ever give a minute to think about what is return false is doing?

Yes, it is cancelling the default behavior but then what is event.preventDefault?

Are we just doing come copy paste and not following the  standards?

So, what is return false is - as we have said that yes it cancel the default behavior of browser but it also have one more event in it which is stopProgation() which for sure we might not needed in many places but just by using return false without any requirement we are also calling stopPropgation()

We should avoid using return false and start using the preventDefault and stopPropogation.

Below is the useful link for same  http://fuelyourcoding.com/jquery-events-stop-misusing-return-false/


Happy Coding!!

No comments:

Post a Comment