Skip to content

Commit e177266

Browse files
authored
Update 100_JS_Que
1 parent 68f12d8 commit e177266

1 file changed

Lines changed: 175 additions & 0 deletions

File tree

100Questions/100_JS_Que

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,181 @@ function getAge(){
365365
getAge();
366366
//Explaination : Use strict wil give a error because it forces to use a proper way of the variable declaration.
367367
----------------------------------------------------------------------
368+
const sum = eval('10*10+5');
369+
console.log(sum); //105
370+
//Explaination : It will perform the numerical operation
371+
----------------------------------------------------------------------------
372+
const obj = {1:"a", 2:"b"}
373+
console.log(obj.hasOwnProperty("1")); //true
374+
console.log(obj.hasOwnProperty(1)); //true
375+
//Explaination : "1" and 1 treat as same.
376+
----------------------------------------------------------------------------
377+
const obj = {a:"one", b: "two", a:"three"}
378+
console.log(obj); // {a:"three", b: "two"}
379+
//Explaination : Key position will be same but tha value get updated with new value in object.
380+
----------------------------------------------------------------------------
381+
for(let i=1; i<5; i++){
382+
if(i==3) continue;
383+
console.log(i); //1,2,4
384+
}
385+
//Explaination : If i =3 then it will not execute the code for 3, but can execute for i=4.
386+
------------------------------------------------------------------------------
387+
const foo = () => console.log("first");
388+
const bar = () => setTimeout(()=> console.log("second"));
389+
const baz = () => console.log("third");
390+
bar();
391+
foo();
392+
baz();
393+
//Explaination : first,third, second. Because asyn operation work post all the syn operation get complete.
394+
----------------------------------------------------------------------------
395+
<div onClick="console.log("first div")">
396+
<div onClick="console.log("second div")">
397+
<button onClick="console.log("button")">
398+
Click Me
399+
</button>
400+
</div>
401+
</div>
402+
//Explaination : button, second div, first div. Even bubbling happened here.
403+
---------------------------------------------------------------------------
404+
const person = {name:'priya'};
405+
function sayHi(age){
406+
return `${this.name} is ${age}`;
407+
}
408+
console.log(sayHi.call(person,21)); //"priya is 21"
409+
console.log(sayHi.bind(person,21)); //it will return a function. //function sayHi(age){ return `${this.name} is ${age}`;}
410+
console.log(sayHi.bind(person,21)()); //"priya is 21"
411+
//Explaination : Bind will always return a function so require to invoke the function.
412+
------------------------------------------------------------------------------
413+
function sayHi(){
414+
return (()=>0)();
415+
}
416+
console.log(typeof sayHi()); //number
417+
//Explaination : sayHi will return anonymous arrow function/IIFE, where it will return 0. type of 0 is number.
418+
----------------------------------------------------------------------------
419+
function sayHi(){
420+
return ()=>0;
421+
}
422+
console.log(typeof sayHi()); //function
423+
console.log(typeof sayHi()()); //function
424+
//Explaination : sayHi will return anonymous arrow function/IIFE, where we didn't invole the arroe function so it will return function.
425+
-----------------------------------------------------------------------------
426+
console.log(typeof typeof 1); //string
427+
//Explaination : typeof 1 is a number and typeof number is a string.
428+
-----------------------------------------------------------------------------
429+
const numbers = [1,2,3];
430+
numbers[6]=11;
431+
console.log(numbers); //[1,2,3,,,,11]
432+
//Explaination : Array store elements in a continuous memory location. It will give empty in between an array.
433+
-------------------------------------------------------------------------------
434+
const numbers = [1,2,3];
435+
numbers[9]=numbers;
436+
console.log(numbers); //[1,2,3,,,,.......]
437+
//Explaination: It will print infinite loop.
438+
-------------------------------------------------------------------------------
439+
console.log(!!null); //false
440+
console.log(!!""); //false
441+
console.log(!!1); //true
442+
//Explaination: !null give true and !!null give false. !1 give false and then !!1 give true.
443+
-------------------------------------------------------------------------------
444+
console.log(setInterval(()=>console.log('Hi'), 1000));
445+
console.log(setInterval(()=>console.log('Hi'), 1000));
446+
console.log(setInterval(()=>console.log('Hi'), 1000));
447+
//Explaination: setInterval will give uniques id to stop. It will give like 1,2,3. so it will print 1,2,3,Hi,Hi, Hi, Hi, Hi, .....so on.
448+
-------------------------------------------------------------------------------
449+
console.log([..."priya"]); //["p","r","i","y","a"]
450+
//Explaination: It will convert into an array.
451+
-------------------------------------------------------------------------------
452+
const firstPromise = new Promise((res, rej)=>{
453+
setTimeout(res, 500, 'one');
454+
})
455+
const secondPromise = new Promise((res, rej)=>{
456+
setTimeout(res, 100, 'second');
457+
})
458+
Promise.race([firstPromise, secondPromise]).then(res => console.log(res));
459+
//Explaination: Race will return only first matching result so it will print 100. For 500 it will take time to execute so it will not get print.
460+
-----------------------------------------------------------------------------------
461+
let person = {name: "priya"};
462+
const numbers = [person];
463+
person = null;
464+
console.log(numbers, person); // [{name : "priya"}] //null
465+
//Explaination: We try to empty the objecti,e person, but still an array i.e, numbers conatin value so it will not create an impact while assigning null to person.
466+
----------------------------------------------------------------------------------
467+
const person = {name: "priya", age: 1000};
468+
for(const item in person){
469+
console.log(item); //name, age
470+
}
471+
//Explaination: For in loop give a keys only.
472+
--------------------------------------------------------------------------------------
473+
let data = 3+4+'5';
474+
console.log(data); //"75"
475+
console.log(typeof data); //string
476+
//Explaination: It will add as a string.
477+
------------------------------------------------------------------------------------------
478+
console.log(typeof 3+4+'5'); //"number45"
479+
//Explaination: operation went from left to right side.
480+
----------------------------------------------------------------------------------------
481+
console.log(typeof (3+4+'5')); //"75" //string
482+
console.log(typeof (3+4+ +'5'));//number
483+
//Explaination: To find out the typeof when the all the operation get complete thrn have to enclose in paranethisis. If we add + plus sign to any string it will convert to a number.
484+
----------------------------------------------------------------------------------------
485+
que 91
486+
----------------------------------------------------------------------------------------
487+
----------------------------------------------------------------------------------------
488+
----------------------------------------------------------------------------------------
489+
490+
491+
492+
493+
494+
495+
496+
497+
498+
499+
500+
501+
502+
503+
504+
505+
506+
507+
508+
509+
510+
511+
512+
513+
514+
515+
516+
517+
518+
519+
520+
521+
522+
523+
524+
525+
526+
527+
528+
529+
530+
531+
532+
533+
534+
535+
536+
537+
538+
539+
540+
541+
542+
368543

369544

370545

0 commit comments

Comments
 (0)