0

Javascript passes primitive values by value and objects by value or reference (depends). So how does javascript pass functions around?

mercury=()=>{
 console.log("eleven")
}
let eleven = mercury
eleven();

so when i pass the function mercury to eleven, is the function passed by value or by reference?

illiteratewriter
  • 4,155
  • 1
  • 23
  • 44
  • 3
    Functions are objects, just like arrays are objects. (That said, a function's *call behaviour* - i.e. what it does - is immutable, so it doesn't make much difference to being passed by value) – Bergi Dec 31 '17 at 17:02
  • I saw that answer, but it didn't speak about functions. Only objects and primitive types – illiteratewriter Dec 31 '17 at 17:04
  • Those links answered the question, but i don't think it is fair to mark it as exact duplicate. :) – illiteratewriter Dec 31 '17 at 17:13
  • Yeah, unfortunately the "exact" bit is part of the canned template and I cannot change it – Bergi Dec 31 '17 at 17:14

0 Answers0