0

I had some doubts for function literals

  1. Why does the function name in function literals have no significance?
  2. Why aren't they important?
  3. Why doesn't the function get invoked when we try to call using the function name in case of function literals?

    var a = function b(){
            //some code
            }
    b(); //Doesn't work
    

Why does the name b have no significance but a does?

I am new to JavaScript and a beginner so any help would be appreciated!

Mohammed Shoaib
  • 344
  • 4
  • 11

1 Answers1

0

Name b has significance only inside function. Outside you must call function via a.

  • Ik that, but why! That's my question! Why doesn't b have significance?! I don't get why... – Mohammed Shoaib Jul 08 '17 at 14:05
  • @MohammedShoaib because it's an expression and does not declare a name, like `var` or `function` does. That's just how it works. – Bergi Jul 08 '17 at 14:08
  • It is usefull when you declare some anonymous function and this function must have access to its own properties. But how? Named function declarations help you in this case. Example: `var a = function b() { b.prop = 42; }`. Without `b` name properties inaccessible. – mentalMedley Jul 10 '17 at 04:47