0

Let's say I've created an array arr through the console.

let a = [1,2,3,4,3,5]

Following will auto evaluate and show the result

a.slice()

enter image description here

Following will only evaluate when you invoke it. (Press Enter)

a.splice()

enter image description here

So, how does the console know that splice will cause mutation and slice will not.

Is there some kind of list of names of mutation causing functions under the hood?

Mooze
  • 436
  • 5
  • 9
  • 2
    How exactly it does that can only be answered by someone knowing the source code of the browser in question. The evaluation is most likely run through an interpreter to get the result. The interpreter could then be configured to throw an error if a mutation would occur instead of actually applying the mutation. This is just a guess though. – pascalpuetz Nov 27 '21 at 11:53
  • Why do you assume that lack of mutation is the sole criterion for display of return value previews? – jsejcksn Nov 27 '21 at 12:04
  • @jsejcksn Because I've tested with many other methods of several objects. The only other "not very common" reason is computation timeout. – Mooze Nov 27 '21 at 12:14

0 Answers0