javascript setting variables code example

Example 1: how to create variables using javascript

var myVar;       //unitialized variable( can be intiallized later )
var number = 1; //number
var string = " hello world " ; //string
var boolean = true ;  //boolean
myVar = function(){  //variable can hold function
  
};

Example 2: how to assign variables in javascript

// data from json: resp = {"home": 1, "landmark": 2}
// Method 1: 
// use ` for add variable
url = `workspace/detail/${resp.home}`;
console.log(url) -> // workspace/detail/1
  
// Method 2: 
// use ' and + for concentrace variable
url = 'workspace/detail/' + resp.home;
console.log(url) -> // workspace/detail/1

Tags:

Html Example