Creating Values in JS

Photo by James Harrison on Unsplash


var name = 'Dash';
var age = 19;
/* Here, we told JavaScript to create a data by the name of 'name' and store a value 'Dash' of string datatype.
We did the same with the age, but this time saving a number datatype in it. */
/* Now, we have 2 variables to operate on. */
  • Can contain alphanumeric, $ and _ only, no spaces allowed
  • Can NOT start with a digit.
  • Can NOT use reserved keyword.

Good Naming Convention

var fullnameofuser = 'Sudesh Kumar Das';
var full_name_of_user = 'Sudesh Kumar Das';
var fullNAMEofUSER = 'Sudesh Kumar Das';
var fullNameOfUser = 'Sudesh Kumar Das';

Creating variables

  • var keyword- Short for variable, it is quite self explanatory.
  • let keyword- A new way of creating variable, which was introduced in ES6.
  • const keyword- Another introduction in 2015 when ES6 was released.
const name = 'Dash';      // can not be changed
var age = 24; // can be changed
let feel = 'Happy'; // can be changed
// We have created the values, now lets try to change their = 'Sudesh'; // will throw an error
age = 19; // variable age has now value of 19
feeling = 'Excited' // same as age, 'Excited' is now the value



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store