1

Are these code rows equal in a sense? Are exist the hidden differences in their operation?

$(document).ready(_ => alert('Hello'));
$(_ => alert('Hello'));
Andrey Bushman
  • 11,712
  • 17
  • 87
  • 182

1 Answers1

1

They are exactly the same. Here are the lines from jQuery() function.

// ...
// HANDLE: $(function)
// Shortcut for document ready
} else if ( jQuery.isFunction( selector ) ) {
    return root.ready !== undefined ?
    root.ready( selector ) :

    // Execute immediately if ready is not present
    selector( jQuery );
}

So you can see, if you provide a function to $() or jQuery() as a first argument, it will act as a shortcut for $(document).ready

Luka Kvavilashvili
  • 1,309
  • 10
  • 13