You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<!DOCTYPE html><htmllang="en"><head><title>bonsaiilabs - DOM 101</title></head><body><h1lang="en" style="color: blue">Learning DOM with <i>bonsaiilabs</i></h1><h3>Team Members</h3><ul><li>Harit Himanshu: @harittweets</li><li>Deeksha Sharma: @deekshasharma25</li></ul></body></html>
/** Example 01 Goal: filter userNames that are valid strings**/letuserNames=['harry22','albert12','bonsaii24','deeksha25',undefined,null];letfiltered=userNames.filter((name)=>typeofname==='string')console.log(filtered)/** Example 02 Goal: filter userNames that are atleast 7 characters long**/letuserNames=['harry22','albert12','bonsaii24','deeksha25',undefined,null];letfiltered=userNames.filter((name)=>typeofname==='string'&&name.length>=7)console.log(filtered)/** Example 03 Goal: Filter all users and their salaries where salary is > 3000Note: This will also contain users that are null**/letuserSalaries=[{user: "harry22",salary: 2000},{user: null,salary: 3300},{user: "bonsaii24",salary: NaN},{user: "deeksha25",salary: 3500},{user: "",salary: 4000},];letfiltered=userSalaries.filter((item)=>item.salary>3000);console.log(filtered)/** Example 04 Goal: Filter all users where salary is > 3000 and user exists**/letuserSalaries=[{user: "harry22",salary: 2000},{user: null,salary: 3300},{user: "bonsaii24",salary: NaN},{user: "deeksha25",salary: 3500},{user: "",salary: 4000},];letfiltered=userSalaries.filter((item)=>item.user&&item.salary>3000);console.log(filtered)/** Example 05 Goal: Filter all the item where name doesnot exist**/letuserSalaries=[{user: "harry22",salary: 2000},{user: null,salary: 3300},{user: "bonsaii24",salary: NaN},{user: "deeksha25",salary: 3500},{user: "",salary: 4000},];letfiltered=userSalaries.filter((item)=>!item.user&&item.salary>3000);console.log(filtered)
'use strict';lets="I love JavaScript"letsplitResult=s.split("love")lets="I love JavaScript"letsplitResult=s.split("like")lets="bonsaiilabs"letsplitResult=s.split()lets="|JavaScript"letsplitResult=s.split("|")lets="|JavaScript|"letsplitResult=s.split("|")lets="bonsaiilabs"letsplitResult=s.split("")lets2="bonsaiilabs,british columbia,BC,Canada"letsplitResult=s.split(",",2)letsplitResult=s.split(",",0)letsplitResult=s.split(",")letsplitResult=s.split(",",-1)
/** * Goal: Insert english2Gpa in the middle of english1Gpa */letenglish1Gpa=[2.3,2.80,2.82];letenglish2Gpa=[2.42,2.47,2.77];letmiddleIndex=Math.floor(english1Gpa.length/2);english1Gpa.splice(middleIndex,0, ...english2Gpa);console.log(english1Gpa);
letemailTemplate=`We, at <company>, believe in providing the best online education on JavaScriptIf you like our content, please hit the like and subscribe to our YouTube channelThank you<Company> team`;letreplaced=emailTemplate.replace("<company>","bonsaiilabs");console.log(replaced)letregex=/<company>/giletreplacedRegEx=emailTemplate.replace(regex,"bonsaiilabs");console.log(replacedRegEx)
varcolors=["#1AB399","#66E64D","#6666FF","#E666B3","#FF3380","#B3B31A","#FF4D4D","#33991A","#809980","#4DB3FF","#999933","#99E6E6","#CC9999","#E666FF","#CCCC00","#4DB380","#4D8066","#991AFF","#E6FF80","#00E680","#9900B3","#4D80CC","#66664D","#1AFF33","#E64D66"];letchangeColor=function(){letnewColorIndex=Math.floor(Math.random(colors.length)*10)letnewColor=colors[newColorIndex]document.body.style.backgroundColor=newColor}letintervalId=setInterval(changeColor,1000)// clearInterval(intervalId) // to clear the interval
An attempt to create a variable in the global object
"use strict"// try with and without this linea=2;console.log(a)
Qualifying this in strict mode
"use strict"// try with and without this linefunctionwhoIsThis(){console.log(this===global)}whoIsThis()
Silent About Error to Throwing Error
Deleting a Variable
"use strict"// try with and without this lineletb=2;console.log(b);deleteb;
Deleting a Function
"use strict"// try with and without this linefunctionecho(me){console.log(me)}echo("bonsaiilabs")delete(echo)
Deleting an argument of a Function
"use strict"// try with and without this linefunctionecho(me){deletemeconsole.log(me)}echo("bonsaiilabs")delete(echo)
Deleting the property of an Object
"use strict"// try with and without this lineletironMan={}Object.defineProperty(ironMan,"name",{value: "Tony Stark",enumerable: true,configurable: false// also the default value})console.log(ironMan)deleteironMan.nameconsole.log(ironMan)
letfruits='Banana,Strawberry,Apple,Peach';//Length of fruitsletlength=fruits.length;console.log('Length of fruits: ',length);//Without endIndex (default endIndex = length - 1)console.log('Without endIndex => ',fruits.substring(2));//startIndex and endIndex are same (returns empty string)console.log('Same startIndex & endIndex => ',fruits.substring(3,3));//index > length of the string (returns the length of the string)console.log('startIndex > length => ',fruits.substring(length+1));console.log('endIndex > length => ',fruits.substring(1,length+2));//startIndex > endIndex (indexes are swapped)console.log('startIndex > endIndex => ',fruits.substring(10,2));//startIndex || endIndex === NaN (index is treated as 0)//startIndex || endIndex < 0 (index is treated as 0)console.log('Invalid indexes => ',fruits.substring(-1));console.log('Invalid indexes => ',fruits.substring(NaN));
letweather="rainy"// Using if statementif(weather==="sunny"){console.log("Happy")}else{console.log("Meh!")}// using ternary operatorweather==="sunny" ? console.log("Happy") : console.log("Meh!")
lettext=`YOU might not make it to the TOP, but if you are doing what you love, there is much more happiness there than being RICH or FAMOUS`;letupper=text.toUpperCase()console.log(upper)letlower=text.toLowerCase()console.log(lower)