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

asked Dec 16, 2021 at 20:42
4
  • 1
    javascript-array-sort-implementation Commented Dec 16, 2021 at 20:45
  • It doesn't compare indices, it compares elements of the array. And why do you need to know that? Commented Dec 16, 2021 at 20:45
  • Does this answer your question? Javascript Array.sort implementation? Commented Dec 16, 2021 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 developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… Commented Dec 16, 2021 at 20:56

1 Answer 1

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.

answered Dec 16, 2021 at 20:50
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.