Q:

javascript var

//choose the best for your solution
var myVariable = 22; //this can be a string or number. var is globally defined

let myVariable = 22; //this can be a string or number. let is block scoped

const myVariable = 22; //this can be a string or number. const is block scoped and can't be reassigned
16
var <variable-name>;

var <variable-name> = <value>;
3

 var text = "";
var i;
for (i = 0; i < 5; i++) {
  text += "The number is " + i + "<br>";
} 
1
// write what ever you want
// one way is
// this is to declare intigers
var a = 10;
//this is to declare strings aka words
var b = "hi";
// the key word var can be replaced by let
//like this
let a = 10;
let b = "hi";
// i recomend using let insted of var
4
// let & var are both editable variables:
var cow = 'moo';
let pig = 'oink';
cow = 10;
pig = 10;
// const is a permanent variable; you cannot change it.
const uncuttableGrass = '\/\/';
uncuttableGrass = '___';
// above throws an error
0
var /*var*/ = /*What it does*/
0
//An array is a type of object intended to be only assigned numeric keys
var tmp = []; // or: var tmp = {}
tmp.one = 1;
JSON.stringify(tmp);

// array:
'[]'

// object:
'{"one":1}'
0

New to Communities?

Join the community