Wednesday, April 28, 2021

Javascript Practice 01: JS Hero - Variables


Question: 

Declare a variable firstname and initialize it with the value 'Lata'.





Answer: 

This is a fairly simple exercise. 
> Can declare variables in 3 ways. 
> var, let & const

var firstname = 'Lata'; or (pre - ES6 Variable) (function scoped)
let firstname = 'Lata'; or (ES6 Variables) (block scoped)
const firstname = 'Lata'; (ES6 Variables) (block scoped)

All the 3 options will work. 
They have different properties.  
You can refer to MDN Webdocs or W3Schools for further information. 

No comments:

Post a Comment