Skip to content
Advertisement

When to use : and = in javascript?

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?

Advertisement

Answer

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

Advertisement