algorithm - JavaScript naming of function -


i'm asking because saw on piece of code:

var myvar = function func(arg){    console.log(arg); } 

i don't understand why function "renamed" func before defined myvar.

can explain interest of doing this, , not just:

var myvar = function(arg){    console.log(arg); } 

thank much!

in first example, have variable named myvar, has reference function named func. function isn't renamed.

in secound example, though, have same variable myvar, in case, it's pointing anonymous function.

the reason choosing number 1 on number 2 better output when errors occur, print function name. in second example, undefined if goes wrong.

edit: found more detailed answer here: why use named function expressions?


Comments

Popular posts from this blog

android - Pass an Serializable object in AIDL -

How to provide Authorization & Authentication using Asp.net, C#? -

How to use Authorization & Authentication in Asp.net, C#? -