VARIABLES

Where do I need them?

CONCEPT

How to visualize a variable?

variables

USING VARIABLES

// create a variable
var age;
// assign a value
age = 23;
// change the value
age = 24;
// read the value and log it
console.log(age);

TYPES

  • Number
  • String
  • Array
  • Object

Example

var length = 16;                                  // Number
var lastName = "Johnson";                         // String
var carNames = ["Saab", "Volvo", "BMW"];          // Array
var person = {firstName:"John", lastName:"Doe"};  // Object

DEBUGGING VAR VALUES

Let's see how to do it with the developer toolbar..

SHOW A VAR VALUE ON THE PAGE

<!DOCTYPE html>
<html>
<body>
<div id="firstNameElement"></div>
<script>
var firstName = "Anna";
document.getElementById("firstNameElement").innerHTML = firstName;
</script>
</body>
</html>