Answers for "how to assign variables in javascript"

41

javascript declare a variable

//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
Posted by: Guest on March-09-2020
1

add variables in javascript

var a = 5;
var b = 2;
var c = a + b;
Posted by: Guest on March-24-2021
2

Create variable javascript

//Assigns the value bar to the variable foo
var foo = bar;
Posted by: Guest on June-16-2020
0

how to declare variables javascript

//variables are a way to easily store data in javascript
//variables are declared by the var keyword, example...
var x = 10;
//or
var dog_name = "daisy";
//which can also be written as 
var dog_name = 'daisy';
//same thing with single quotes and double quotes
Posted by: Guest on July-22-2020
0

how to add a variable in js

var x = 5;         // assign the value 5 to x
Posted by: Guest on November-26-2020
0

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
Posted by: Guest on March-25-2021

Code answers related to "how to assign variables in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language