// The code above is around 5-6 lines, which was resolved in 1 line above.
// Switch Statement
varjob="software engineer";
switch(job){
case"software engineer":
case"coder":
case"developer":
console.log(name+" is a Software Developer.");
break;
case"teacher":
case"instructor":
case"professor":
console.log(name+" teaches people how to code.");
break;
case"driver":
console.log(name+" is driver.");
break;
case"designer":
case"architect":
console.log(name+" is a system designer/architect.");
break;
case"painter":
case"artist":
console.log(name+" is an artist.");
default:
console.log(name+" does something else.");
// For the default case, no need of a break statement because after this case, there is no other case. Therefore, the code never keeps on running after this.
}
// if (age < 13)
// console.log(lastName + " is a boy.");
// else if (age >= 13 && age < 20)
// console.log(lastName + " is a teenager.");
// else if (age >= 20 && age < 30)
// console.log(lastName + " is a young man.");
// else console.log(lastName + " is a man.");
// The same code above can be written using switch statement as follows:
switch(true){
caseage<13:
console.log(lastName+" is a boy.");
break;
caseage>=13&&age<20:
console.log(lastName+" is a teenager.");
break;
caseage>=20&&age<30:
console.log(lastName+" is a young man.");
break;
default:
console.log(lastName+" is a man.");
}
/**
* Truthy & Falsy Values.
* Equality Operators.
*/
// falsy values: undefined, null, 0, '', NaN
// truthy values: NOT falsy values
// Truthy & Falsy Values
varheight;
height='';// 1254, 'forty five', etc.
if(height||height===0){
console.log("Variable is defined.");
}else{
console.log("Variable is NOT defined.");
}
// Equality Operators
// == : This equality operator is used when we don't want strict comparison between two variables/values. Aka: Type Coercion Equality Operator.
// === : used to strict comparison of equality between two vars/vals.