xxxxxxxxxx
//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;
xxxxxxxxxx
// 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
xxxxxxxxxx
// 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
xxxxxxxxxx
var example = "hello";
document.write(example);// it will say hello when it runs
xxxxxxxxxx
// 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
xxxxxxxxxx
////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;
xxxxxxxxxx
function x() {
y = 1; // Genera un ReferenceError in strict mode
var z = 2;
}
x();
console.log(y); // scrive "1" in console
console.log(z); // Genera un ReferenceError: z non è definita fuori dalla funzione x
xxxxxxxxxx
let x = "Hello JavaScript";
let x = 0;
// SyntaxError: 'x' has already been declared