//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
// here are the ways to define variables
var x = "hi"; // for global variables
let x = "hi"; // for block-scoped variables
const x = "hi"; // for block-scoped variables which can not be reassigned
//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
//You can make a variable by using:
var variable-name = 'defenition of the variable';
// Or you can use
let variable-name = 'defenition of the variable';
////We can define variables in 3 ways {var,let,const}///////
////syntax- var variable_name=value;
///// let variable_name=value;
/////const variable_name=value;
var myfristvariable="neha jaiswal";
const mysecondvariable=80;
let mythirdvar=abc;
//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
var myString = "string"; //var can be redefined
var myInt = 34; //var can be redefined
const myString2 = "string"; //const cannot be redefined
const myInt2 = 69; //const cannot be redefined
var a; // variable
var b = "init"; // string
var c = "Hi" + " " + "Joe"; // = "Hi Joe"
var d = 1 + 2 + "3"; // = "33"
var e = [2,3,5,8]; // array
var f = false; // boolean
var g = /()/; // RegEx
var h = function(){}; // function object
const PI = 3.14; // constant
var a = 1, b = 2, c = a + b; // one line
let z = 'zzz'; // block scope local variable
// You can change the variable name and the value that i filled in. (witch is variable)
var variable = 47; // You can make this a string, a number, a boleean, an array and a object, but var is globally defined.
let variable = "a string" // As you can see i put a string and you can test it, it works. let is block scoped if you asked.
const variable = true // const is for if you want a variable not to change. So like pi if you made that a const or a variable (look at following example)
const pi = 3.14159265358979323846 // So now if you wish to add pi to calculate something you just type: "pi"
/*Variables declared with var, let and const are quite similar when declared outside a block.
They all have Global Scope:*/
var x = 2; // Global scope
let x = 2; // Global scope
const x = 2; // Global scope
//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!!!
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
};
var a; // variable
var b = "init"; // string
var c = "Hi" + " " + "Joe"; // = "Hi Joe"
var d = 1 + 2 + "3"; // = "33"
var e = [2,3,5,8]; // array
var f = false; // boolean
var g = /()/; // RegEx
var h = function(){}; // function object
const PI = 3.14; // constant
var a = 1, b = 2, c = a + b; // one line
let z = 'zzz'; // block scope local variable