0

I need to find out how exactly a function works, so where can i find the source code of function in Javascript ?

For example: arr.sort(function(a, b){return a-b});

this function sort() gonna sort all index of an array.

But i don't know how this function compare all the Index to each other specifically

black
  • 21
  • 3
  • 1
    [javascript-array-sort-implementation](https://stackoverflow.com/questions/234683/javascript-array-sort-implementation) – Mara Black Dec 16 '21 at 20:45
  • It doesn't compare indices, it compares elements of the array. And why do you need to know that? – UnholySheep Dec 16 '21 at 20:45
  • Does this answer your question? [Javascript Array.sort implementation?](https://stackoverflow.com/questions/234683/javascript-array-sort-implementation) – pilchard Dec 16 '21 at 20:48
  • sort() is a method, that is not declared in a script but built-in in the browser within the javascript support module. In theory there is not only one source since it is implemented in the google chrome source, opera browser source etc. Indeed on all the browsers or Javascript interpreter just to include also node.js use case the function should be working at the same way so you could check the Mozilla related documentation here to find more about it https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort – A. Lion Dec 16 '21 at 20:56

1 Answers1

1

To direct answer the question you asked, you can find function source code like this:

console.log([].sort);

or

console.log(myFunc);

This works with any function.

ControlAltDel
  • 33,923
  • 10
  • 53
  • 80