• Liz
    link
    fedilink
    English
    41 year ago

    I’m not a programmer but I took a class in JavaScript. Unless I’m misunderstanding what you mean by reference, I don’t recall that feature of the language. Can you explain?

    • @PeteZ
      link
      11 year ago

      A language reference (a manual). It’s not a language feature.

    • @EatBorekYouWreck
      link
      English
      11 year ago

      What I think he meant is that in JS every object is a reference or a pointer. This means that instead of the variable be the place in memory where the data is, the variable holds the address of where the data lives. This helps languages like JS and Python have variables that changes their types (you can assign a=true and later a=3 and everything will be fine). A non reference variable, as you can find in languages like C and Rust, is defined by its memory size statically, and the program can just pre-allocate a continuous block of memory that is enough for all the needed variables. This helps your cpu cache and access variables more efficiently. In reference types, memory can end up anywhere on your memory because it is allocated dynamically at runtime, so you access whatever memory that is free and available at the moment. Also the extra step of following a pointer just to get to a block containing a boolean (literally just one bit of memory) compounds and adds up to be actually noticeable in long calculations.