Answers for "how to create a variable 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
3

how to write a variable in js

//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
Posted by: Guest on June-03-2020
6

js variable

var Number = 5;
var String = "Hi!";
var boolen1 = true;
var boolen2 = false;
var array = [11, "Hi!", true];
var object = {age:11, speach:"Hi!", likes_Bananas:true};
Posted by: Guest on June-21-2020
6

javascript variable

var user_name = prompt("Please enter your name:", "Type here");
alert("Hello " + user_name);
Posted by: Guest on November-03-2020
1

how to declare a variable js

//let and var are both editable variables and can be changed later on in your program;
let dog = 'Woof';
//dog is equal to the string 'Woof';
dog = false;
//You can changed the value of dog now because it was defined with let and not const;

let cow = 'Moo';
//cow is equal to the string 'Moo';
cow = true;
//You can change the value of cow later on because it is not defined with const;

//const is used when declaring a variable that can't be changed later on -- const stands for constant;
const pig = 'oink';
//This assigns the string 'oink' to pig which can not be changed because it is defined with const;
pig = 'snort';
//Above throws an error
//Good Job you now know how to declare variables using JavaScript!!!
Posted by: Guest on July-07-2020
0

how to create a variable in javascript

// you an pass in strings or a number 

var exampleVariable = 'Example string' // this is a normal string 
var anotherExample = 839;
Posted by: Guest on June-25-2021

Code answers related to "how to create a variable in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language