1. What is the difference between undefined and not defined in JavaScript? > there is declaration but not definition vs there is no declaration 2. What will be the output of the code below? ```javascript= var y = 1; if (function f(){}) { y += typeof f; } console.log(y); var k = 1; if (1) { eval(function foo(){}); k += typeof foo; } console.log(k); var k = 1; if (1) { function foo(){}; k += typeof foo; } console.log(k); ``` > The if condition statement evaluates using eval > if statement code executes at run time, and the statement inside the if condition is evaluated during run time. 3. What is the drawback of creating true private methods in JavaScript? > memory-inefficient, as a new copy of the method would be created for each instance. 4. Write a mul function which will produce the following outputs when invoked: ```javascript= function mul (x) { return function (y) { // anonymous function return function (z) { // anonymous function return x * y * z; }; }; } multi = x => y => z => x * y * z; ``` A function is an instance of the Object type A function can have properties and has a link back to its constructor method A function can be stored as a variable A function can be pass as a parameter to another function A function can be returned from another function --- 5. How do you check if an object is an array or not? > One of the best use cases of type-checking an object is when we do method overloading in JavaScript. For example, let's say we have a method called greet, which takes one single string and also a list of strings. To make our greet method workable in both situations, we need to know what kind of parameter is being passed. ```javascript= Array.isArray([1,4,7]) true Object.prototype.toString.call([1,44,7]) "[object Array]" Object.prototype.toString.call({'jkj':0}) "[object Object]" Object.prototype.toString.call('okokk') "[object String]" Object.prototype.toString.call(09) "[object Number]" ``` --- 6. What will be the output of the following code? ```javascript= var output = (function(x){ delete x; return x; })(0); console.log(output); ``` >The output would be 0. The delete operator is used to delete properties from an object. Here x is not an object but a local variable. delete operators don't affect local variables. --- 7. What will be the output of the following code? ```javascript= var x = 1; var output = (function(){ delete x; return x; })(); console.log(output); ``` > The output would be 1. The delete operator is used to delete the property of an object. Here x is not an object, but rather it's the global variable of type number. --- 8. What will be the output of the code below? ```javascript= var x = { foo : 1}; var output = (function(){ delete x.foo; return x.foo; })(); console.log(output); ``` > The delete operator is used to delete the property of an object. Here, x is an object which has the property foo, and as it is a self-invoking function, we will delete the foo property from object x. After doing so, when we try to reference a deleted property foo, the result is undefined. --- 9. What will be the output of the code below? ```javascript= var Employee = { company: 'xyz' } var emp1 = Object.create(Employee); delete emp1.company console.log(emp1.company); ``` >The output would be xyz. Here, emp1 object has company as its prototype property. The delete operator doesn't delete prototype property. emp1 object doesn't have company as its own property. You can test it console.log(emp1.hasOwnProperty('company')); //output : false. However, we can delete the company property directly from theEmployee object using delete Employee.company. Or, we can also delete the emp1 object using the `__proto__` property `delete emp1.__proto__.company`. ------ 10. What is undefined x 1 in JavaScript? > is just way of displaying an array's uninitialised index in old Chrome. ```javascript= var trees = ["redwood","bay","cedar","oak","maple"]; delete trees[3]; console.log(trees); ``` > in old chrome ```javascript= ["redwood", "bay", "cedar", undefined × 1, "maple"] ``` > in new chrome ```javascript= ["redwood", "bay", "cedar", empty, "maple"] ``` > in firefox ```javascript= Array(5) [ "redwood", "bay", "cedar", <1 empty slot>, "maple" ] ``` ---- 11. What will be the output of the code below? ```javascript= var trees = ["xyz","xxxx","test","ryan","apple"]; delete trees[3]; console.log(trees.length); ``` >5 --- 12. What will be the output of the code below? ```javascript= var bar = true; console.log(bar + 0); console.log(bar + "xyz"); console.log(bar + true); console.log(bar + false); ``` >Number + Number -> Addition Boolean + Number -> Addition Boolean + Number -> Addition Number + String -> Concatenation String + Boolean -> Concatenation String + String -> Concatenation > 1, "truexyz", 2, 1 ---