Skip to content

JS Variable Keywords

coloradokim edited this page Mar 5, 2018 · 2 revisions

const, let, var

Resources

Variables

  • Variables provide developers a way to store a value
  • Once a variable is declared, the name of the variable is called an identifier
  • For example, const name = 'kim'; `name is the identifier
  • In JavaScript, variable identifiers can contain the letters (a-z), numbers (0-9), underscores (_) and the dollar sign ($)

Explanations and Use Cases

const

Example:

const API_URL = asdlkfjasldkfjasdf.com/v1/plants;

function filterData(){
    const result = {};
    // code here
    return resut;
}

let

  • Used when the value of the variable will be reassigned
  • Most commonly used in for loops
  • Block scope: can see/access what is inside the curly braces. can be a function, loop or conditional.

var

  • In ES5 and prior versions of ECMAScript, var was the only variable declaration keyword
  • Avoid var
  • When is var used in ES6?
  • function scope: can see/has access to anything within the curly braces of a function
Clone this wiki locally