Skip to content

Commit 68f12d8

Browse files
authored
Update 100_JS_Que
1 parent 4b8f29b commit 68f12d8

1 file changed

Lines changed: 104 additions & 2 deletions

File tree

100Questions/100_JS_Que

Lines changed: 104 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,110 @@ navigator.plateform we can use it. //win32
261261
let for = 100; //Error
262262
//Explaination : For is a reserved keyword.
263263
-------------------------------------------------------------------------------
264-
Que: 51
265-
264+
function fruit(){
265+
console.log(name); //undefined
266+
console.log(price); //Error
267+
var name = "priya";
268+
let price = 1000;
269+
}
270+
fruit()
271+
//Explaination : Hoisting concept used here. Error because in LET declaration first then only we can use it. but in var we can use brfore its declaration.
272+
-------------------------------------------------------------------------------
273+
for(var i=0; i<3; i++){ //i=0 //1 //2 //3
274+
setTimeout(()=>console.log(i),1) // 3,3,3
275+
}
276+
//Explaination : Var is a global variable. Firstly Sync code get executed then async code will start to execute. so i value incremented from 0 to 3 when pointer reaches to setTimeout so it will print 3 thrice time.
277+
---------------------------------------------------
278+
for(let i=0; i<3; i++){ //i=0 //1 //2 //3
279+
setTimeout(()=>console.log(i),1) //0 //1 //2
280+
}
281+
//Explaination : LET is a block scope. so it will print 0,1,2. Its having own islocated scope.
282+
----------------------------------------------------
283+
console.log(+true); //1
284+
console.log(typeof +true); //number
285+
//Explaination : if we write + in front of anything then it will convert into a number.
286+
----------------------------------------------------
287+
console.log(!"priya"); //false
288+
console.log(typeof ("priya")); //string
289+
//Explaination : ! will give either true/false.! means false and !! means true.
290+
----------------------------------------------------
291+
let data = "size";
292+
const bird = {size : "small"}
293+
console.log(bird[data]); //small
294+
console.log(bird["size"]); //small
295+
console.log(bird.size); //small
296+
console.log(bird.data); //undefined
297+
//Explaination : If we wants to access variable with object then use [] notation(. notation will not work).
298+
------------------------------------------------------
299+
let c = {name : "priya"};
300+
let d;
301+
d=c;
302+
c.name = "supriya";
303+
console.log(d.name); //supriya
304+
//Explaination : Using assignment operator we are accessing the same memory allocation.
305+
-------------------------------------------------------
306+
var x;
307+
var x=10;
308+
console.log(x); //10
309+
//Explaination : Can be declare multiple times.
310+
---------------------------------------------------------
311+
var x;
312+
let x=10;
313+
console.log(x); //Error
314+
//Explaination : Can't be declare multiple times with LET.
315+
----------------------------------------------------------
316+
let a = 3;
317+
let b = new Number(3);
318+
console.log(a == b); //true
319+
console.log(a === b); //false
320+
console.log(typeof b); //object
321+
//Explaination : === will give false because a will give number but b will give an object.
322+
-------------------------------------------------------
323+
let name;
324+
nmae ={}; //wrong variable name i wrote
325+
console.log(name); //undefined
326+
//Explaination : by default it wil be undefined if we declare first.
327+
---------------------------------------------------------
328+
function first(){
329+
console.log("Woof!!"); //Woof!!
330+
}
331+
first.name = "apple";
332+
first();
333+
//Explaination : To add the property with a function then it will not create a impact.
334+
----------------------------------------------------------
335+
function sum(a,b){
336+
return a+b;
337+
}
338+
console.log(sum(1, "2")); //12
339+
//Explaination : 2 is passed as a string so it will get concat. num+string = string
340+
------------------------------------------------------------
341+
let num = 0;
342+
console.log(num++); //0
343+
console.log(++num); //2
344+
console.log(num); //2
345+
//Explaination : ++ will increase the value by 1. preincrement and postincrement used here.
346+
--------------------------------------------------------------
347+
function getAge(...args){ //[1000]
348+
console.log(typeof args); //object
349+
}
350+
getAge(1000);
351+
//Explaination : typeof args means typeof an array means typeof [] is object.
352+
--------------------------------------------------------------
353+
function getAge(){
354+
age = 1000;
355+
console.log(age); //1000
356+
}
357+
getAge();
358+
//Explaination : if we didn't declare with Var/Let/const then by default it will become as a Var.
359+
------------------------------------------------------------------
360+
function getAge(){
361+
'use strict'
362+
age = 1000;
363+
console.log(age); //error
364+
}
365+
getAge();
366+
//Explaination : Use strict wil give a error because it forces to use a proper way of the variable declaration.
367+
----------------------------------------------------------------------
266368

267369

268370

0 commit comments

Comments
 (0)