So many time in interview, we will get this question. But maximum people give the answer of one or two approach of writing function in Jquery.
we can write the the function in Jquery 4 ways. I will include all the 4 ways in given below example.
Complete source code as given below
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="../Scripts/jquery.min.js"></script> <script> //1 Standard ways jQuery(document).ready(function () { alert("Hello from Jquery"); }); //2 Standard ways using $ alias $(document).ready(function () { alert("Hello from Jquery using $"); }); //3 using shortcut $(function () { alert("Hello from Jquery using shortcut"); }); //4 Shortcut with failsafe usage of $ jQuery(function ($) { alert("Hello from Jquery with Failsafe"); }); </script> </head> <body> </body> </html>
One thought on “Different ways to write Jquery function (Part 2)”