Posts

Showing posts from January, 2021

Template strings in javascript (understanding ES6)

Image
 Template strings in javascript (understanding ES6) Template strings are basically the latest way of concatenating strings or be it functions and has come alive with the ES6 version of ecmaScript. So let us understand how we use Template String to concatenate or join two given strings before ES6 and once it has come: < script >      var  FirstName =  "Praveen" ;      var  MiddleName =  "Kumar" ;      var  LastName =  "Yadav" ;     document.write( ` ${ FirstName }   ${ MiddleName }   ${ LastName } ` );     console.log( ` ${ FirstName }            ${ MiddleName }              ${ LastName } ` );         // OLD WAY OF CONCATINATION OF STRINGS              /*  document.write(FirstName + MiddleName + LastName);         console.log(FirstName + MiddleName + LastName);     */ </ script > OUTPUT: TEMPLATE STRING IN JAVASCRIPT ES6 VERSION So with this example we understood that to use template string we have to use backlash followed by curly braces  `{}`

Use of Let, Var and Const in Javascript along with their Scopes

Image
 Use of Let, Var and Const in Javascript along with their Scopes The data type "var" can be used to redeclare or assign a variable n number of times without any troubles. But the data type "Let" can be initialised only once and cannot be initialized again and again. However it can be assigned n number of times but it cannot be initialised. What i essentially mean can be understood with the below given example: CASE 1 ( VAR Data type): Var Name = "Rishu";  // here i have initialised my variable "Name" and declared its value as                                               //   well as "Rishu"; Var Name = "Calc";    // re initialized the value of Name as "Calc"  console.log(Name);     // It will print Calc without any error CASE 2 ( Let Data type): Let Name = "Rishu";  // here i have initialised my variable "Name" and declared its value as                                                 //   well as