Qus 1. Given a string "Hello" & write a code to print the count of the chars available to it & create the object like this
{"H":1, "e":1, "l":2, "o":1}
Soln:
var word = "Hello";
temp = [];
arr.forEach(function(chr){
temp[chr] = word.split(chr).length - 1;
});
var finalObj = Object.assign({}, temp);
console.log(finalObj);
Qus 2. Output of the below given program -
Program:
console.log(1);
console.log(2);
setTimeout(()=>{
console.log(3);
}, 3000);
console.log(4);
console.log(5);
Output:
1
2
4
5
3
Qus 3. Output of the below given program & what if replaces the inner function as a arrow method -
Program:
var personObj = {
first_name: 'Alex',
last_name: 'Waugh',
getName: function(){
console.log( this.first_name, this.last_name)
}
}
personObj.getName();
Output:
Alex Waugh
//if replaced the getName to arrow method then what will be the output
undefined undefined
No comments:
Post a Comment