Learn JavaScript the Eloquent Way-JavaScript Variables

Subscribe to my newsletter and never miss my upcoming articles

Defining a Variable

The most common practice of defining a variable is -

let firstName = 'John';

Some rules for defining Variables are :

  • Cannot be a reserved Keyword
  • Should be meaningful
  • Cannot start with a number
  • Cannot contain a space( ) or hyphen(-)
  • use camel notation eg- firstName lastName

Defining Constants-

const pi = 3.142

Types of Variables

let name = 'John'; //String Literal
let age = 30; // Number Literal
let isApproved = True; // Boolean Literal
let firstName = undefined;
let selectedColour = null;

No Comments Yet