Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's this "function a/<()" in the developer console?

While playing with the Developer Console in Firefox, I tried doing this:

var a = b => c => c;

and then this:

a(1)

I expected the result to be function() (corresponding to c => c), but this was displayed instead:

function a/<()

What is the meaning of this expression? It clearly isn't legal Javascript, since neither / nor < are valid characters for a function name.

The same happens using the regular notation for functions, i.e. var a = function(b) { return function(c) { return c; } }.

Here is a screenshot:

enter image description here

Edit: I tried the following

var a = b => c => d => d;
a(1)

and the result is

a/</<()

which makes me think it's some kind of lesser-known shorthand notation.

like image 807
Giulio Muscarello Avatar asked Dec 28 '15 19:12

Giulio Muscarello


People also ask

What is named function in JavaScript?

Named Functions: In JavaScript, named functions are simply a way of referring to a function that employs the function keyword followed by a name that can be used as a callback to that function. Normal functions with a name or identifier are known as named functions.

How do you check if a function is executed in JavaScript?

You can check for a function using the typeof keyword, which will return "function" if given the name of any JavaScript function.


1 Answers

Commenters on the relative issue on bugzilla have pointed out that it's part of a naming convention for anonymous function.

In particular,

  • a/b - inner b of var a = function() { var b = function() {}; }
  • a< - flags a "contributor" or basically some helper function which contributes to the function named a by being anonymous inside it.

So a/<() means that there is an anonymous function was declared in the body of a.

like image 194
Giulio Muscarello Avatar answered Sep 17 '22 08:09

Giulio Muscarello