Sign in Go Pro

Beginning JavaScript for React Native

Variables: var, let, and const


Up next



Variables in JavaScript can be defined with var, let, or const. In general:

  • Don't use var anymore
  • Use const most of the time (as often as possible)
  • Use let if the value will be changing

Using const is a signal to other developers that the value will not be changing. You also get an error message if the value does change; so you can be sure the value of that variable will not change.

Be careful though - because a const object may not change reference, but the values on that object may change value.

Summary of Content:

  • The difference between var, let and const
  • How to define, name a variable, and assign a variable
  • A const reference will never change, but the values of the object referenced by that const may change (but this is an anti-pattern)
  • Passed by value vs passed by reference
  • Reassigning a variable to a different type





There are no comments on this lesson, start the conversation below ...

You need to go PRO to post comments.

Lessons in Beginning JavaScript for React Native