e.preventDefault();
It simply stops the default action of an element.
Instance Ex.:-
prevents the hyperlink from following the URL, prevents the submit button to submit the form. When you have many event handlers and you just want to prevent default event from occuring, & occuring from many times, for that we need to use in the top of the function().
Reason:-
The reason to use e.preventDefault();
is that in our code so something goes wrong in the code, then it will allow to execute the link or form to get submitted or allow to execute or allow whatever action you need to do. & link or submit button will get submitted & still allow further propagation of the event.
<!DOCTYPE html>_x000D_
<html lang="en" dir="ltr">_x000D_
<head>_x000D_
<meta charset="utf-8">_x000D_
<title></title>_x000D_
</head>_x000D_
<body>_x000D_
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>_x000D_
<a href="https://www.google.com" onclick="doSomethingElse()">Preventsss page from redirect</a>_x000D_
<script type="text/javascript">_x000D_
function doSomethingElse(){_x000D_
console.log("This is Test...");_x000D_
}_x000D_
$("a").click(function(e){_x000D_
e.preventDefault(); _x000D_
});_x000D_
</script>_x000D_
</body>_x000D_
</html>
_x000D_
return False;
It simply stops the execution of the function().
"return false;
" will end the whole execution of process.
Reason:-
The reason to use return false; is that you don't want to execute the function any more in strictly mode.
<!DOCTYPE html>_x000D_
<html lang="en" dir="ltr">_x000D_
<head>_x000D_
<meta charset="utf-8">_x000D_
<title></title>_x000D_
</head>_x000D_
<body>_x000D_
<a href="#" onclick="returnFalse();">Blah</a>_x000D_
<script type="text/javascript">_x000D_
function returnFalse(){_x000D_
console.log("returns false without location redirection....")_x000D_
return false;_x000D_
location.href = "http://www.google.com/";_x000D_
_x000D_
}_x000D_
</script>_x000D_
</body>_x000D_
</html>
_x000D_