DEV Community

loading...
Cover image for Learn JavaScript the Eloquent Way-JavaScript Variables

Learn JavaScript the Eloquent Way-JavaScript Variables

envoy_ profile image Envoy-VC ・1 min read

Defining a Variable

The most common practice of defining a variable is -

let firstName = 'John';
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Types of Variables

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

Discussion (0)

pic
Editor guide