I am a newbie in Javascript. Recently, while using React for a project, I couldn't make my program work as I wanted it to until a friend of mine pointed out that all variable assignments in Javascript are by reference to increase performance. So I cloned most of my variables instead and now it worked.
But this defeats the purpose of this Javascript quirk which is to increase speed. So I figured that I only needed to clone the states that I will perform calculations to so that I can reuse the state's original values later.
Besides this, are there any hard and fast rules about when I should/should not clone variables in Javascript?