What are the different ways of defining functions in javascript? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What are the different ways of defining functions in javascript?

please tell me as many as possible in brief, thankyou.

2nd Feb 2017, 11:43 AM
Anita Sharma
Anita Sharma - avatar
2 Answers
+ 3
Basically, There are two types of functions. First declared by using 'function' keyword like this - function myFunc(){ // your code } // how to call these functions myFunc(); And second that are called anonymous functions (without a name). Like this- var myFunc = function(){ // your code }; // how to call the function myFunc(); Can you see the difference. First type of functions are real functions. Second type of functions are used to create methods of JavaScript objects.
2nd Feb 2017, 12:52 PM
Vikash Pal
Vikash Pal - avatar
+ 2
you can define a function by 'function' keyword. function myFunc(){ // all the code. }
2nd Feb 2017, 12:43 PM
Vikash Pal
Vikash Pal - avatar