Javascript
Variables
Summary
This page shows examples of how to declare and use variables in Javascript.
Discussion
Declaring variables:
const myVariable = ["item", 2, 4, "stuff"];
Const declarations are immutable
const a = 1 a = 2 --> // error because we are redfining the variable
let declartions are mutable
let a = 1
a = 2 --> // a, now returns 2
- Data types:
- string:
"stuff"
- integer:
42
- float:
3.14
- bool:
false
- array:
["things", "go", "here"]
- string:
- Access items in an array through indices:
myArray[0];
Examples
- String:
const myString = 'hello';
- integer:
const myInt = 42;
- float:
const myFloat = 3.14;
- bool:
let myBool = false;
- array:
const myArray = ["things", "go", "here"];