Conditions , IF and Switch
var x = 10;
if(x == 10){
console.log("x is equal to 10");
}
else{
console.log("false");
}
// diffrent between == and ===
// "==" only check value and "===" strict check list (check typeof like variable value is string or number etc.)
// Ternary operator
(x == 10) ? "true" : "false"
// Switch Case
const html = "div";
switch(html){
case "div" :
console.log("value is div");
break;
case "h1" :
console.log("value is h1");
break;
default :
console.log("value is defualt");
break;
}
Function
//Function in javascript
function showval(val){
console.log("function running "+val);
}
// call function
showval("true");
Arrow Functions
// ES6 Function
const showval = (val) =>{
console.log("function running "+val);
}
// call function
showval("true");
Constructor Functions
// Constructor Object
function mobile(brand,model,price){
this.brand = brand;
this.model = model;
this.price = price;
}
const s2 = new mobile(oppo,s2,$150);
console.log(s2);
ES6 Classes
//Class in ES6
class mobile{
constructor(brand,launchdate,price){
this.brand = brand;
this.launchdate = new Date(launchdate);
this.price = price;
}
getFullyear(){
return this.launchdate.getDate();
}
}
const s2 = new mobile(oppo,10/10/2018,$150);
console.log(s2);
0 Comments
Post a Comment