Answers for "js variables"

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
4

js variables

//Making variables with let:
let numberOfFriends = 1;

//Incrementing:
numberOfFriends += 3; //numberOfFriends is now 4

// Variables with const
const minimumAge = 21; //CANNOT REASSIGN!

//Booleans - true or false values
true;
false;
let isHappy = true;

//Naming Conventions
// Use upper camel-cased names:
let numberOfChickens = 6; //GOOD
// NOT THE JS WAY:
// let number_of_chickens = 6;
Posted by: Guest on January-04-2021
2

js variables

// JS Variables
var varExample = "var"; // var is use for variable in js the problem with it that it has complicated scope 
let letExample = "let"; // let is pretty much same as var the only thing which make its more varriable is its variable scope.
const constExample = "const"; // const is use for constant values and this variable scope is sane as let
Posted by: Guest on April-25-2021
1

js variables

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

js variables

// Can be a number
var myVar = 21
//Can be a string
var myVar2 = "string"
// Used in a function
function printVar(parvar) {
  print(parvar);
}

printVar(myVar2);
// prints "string"
printVar(myVar);
// prints 21
Posted by: Guest on July-31-2021
0

js variables

// 3 ways to create

var mrVariable = 'x'; // You can set it to to a string ( '' ) or no. ( 0 ). It 
// is globally defined

let myVariaible2 = 'y'; // You can set it to string or no. let is block scoped

const myVariable = 'z'; // It is block scoped, can be a string or no. and can't 
//be reassigned
Posted by: Guest on August-26-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language