[SOLVED] When to use : and = in javascript?

Issue

I have these code snippet.

 const initialAuthState = {
  isAuthenticated:false
};

and

function login(state){
      state.isAuthenticated=true;
    }

How do I know when to use ‘=’ and when to use ‘:’ in javascript?

Solution

= inside a function or code block (like inside an if/else/for/while etc.), : inside of objects.

Answered By – Samathingamajig

Answer Checked By – Clifford M. (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published.