JavaScript execute line by line, so effect is not finished and JavaScript code can be run.So overcome this problem jQuery introduce new concept of callback function, In the jQuery a callback function run when effect is finish.
Syntax to create callback function:
$(selector).hide(speed,callback);
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("p").slideToggle("10000", function(){
alert("The is callback function");
});
});
});
</script>
</head>
<body>
<button>Click Here</button>
<p>This is a paragraph with little content.</p>
</body>
</html>