Skip to main content

Posts

Showing posts with the label Interview

ES 6 Interview Question and Answer - Intermediate Level

The interview questions posted in the article are based on let, rest/spread, default parameter, destructuring, object/template literals, etc introduced in ES 6.
Find the output of the code in each question.

// Question 1 let a = 2; if (a > 1) { let b = a * 3; console.log(b); for (let i = a; i <= b; i++) { let j = i + 10; console.log(j); } let c = a + b; console.log(c); }
// Question 2 function foo() { console.log(a); console.log(b); var a; let b; } foo();
//Question 3 var funcs = []; for (let i = 0; i < 5; i++) { funcs.push(function() { console.log(i); }); } funcs[3]();
//Question 4 var a = [2, 3, 4]; var b = [1, ...a, 5]; console.log(b);

//Question 5 function foo(x, y, ...z) { console.log(x, y, z); } foo(1, 2, 3, 4, 5);
//Question 6 function foo(x = 11, y = 31) { console.log(x + y); } foo(); foo(5, 6); foo(0, 42); foo(5); foo(5, undefined); foo(5, null)…

Javascript Hoisting Interview Question and Answers - 5

In this post,I have tried to cover all the types of possible interview questions and answers on hoisting. If you are not familiar with the hoisting, I would highly recommend you to go to my post on hoisting. Once you are comfortable with the topic, you can attempt these questions. Understanding the type of question will help you to answer. I have provided the hint after each question. All the answers are given at the end of the post.
//Question 1 console.log('bar:', bar) bar = 15 var foo = 1 console.log(foo, bar) var bar Hint: Basics of hoisting //Question 2 var foo = 5 console.log('foo:', foo) var foo; var bar = 10; var bar; console.log('bar:', bar) var baz = 10 var baz = 12 console.log('baz:', baz) Hint: Basics of hoisting //Question 3 function foo() { function bar() { return 5 } return bar() function bar() { return 10 } } console.log(foo()); Hint: Think what happens if two functions wit…

Javascript Interview Question and Answer - 4

In this blog, we will see 10 very simple but must know interview Question and answers.

1. What is the relation between JavaScript and ECMA Script?
Javascript is a scripting language used for web or webapplication development whereas ECMA Script is a  like a guideline and rules for Javascript.

2. What is Callback?
A callback is a JavaScript function passed to some other function as an argument which is to be executed after the main function has finished executing. function callbackFun(x) {     console.log(x);    }  function mainFun(num, callback) {     console.log("Hi I am going to call callback");    callback(num);  mainFun(7, callbackFun);
3. What is Closure?
A closure is a feature in JavaScript where an inner function has access to the outer (enclosing) function's variables. Learn more about closure.

4. What is namespace in JavaScript?
Namespace is used for grouping the desired functions, variables etc. under a unique name. This improves modularity in the coding and enable…

Javascript Interview Question and Answer - 3

In this post, I have discussed 5 basic javascript question and answer that is mostly asked in the interviews. Most of the time interviewer starts the interview with some of these basic questions.
So here we have

Q1. What is the difference between == and ===?

Solution : When we want to test the equality of two values(LHS and RHS), we use == or ===.
== is basically used to check if the two values are equal or not,and we are not considering their datatype. e.g.
if we check

5 == "5"   // true as values are equal
undefined = null   //  true as both represents NO VALUE

In case of ===, we not only consider the values but the datatype as well.e.g.

5 === "5"   // false as though values are equal but datatypes are different

Similarly

undefined === null  //  false, as datatype of undefined and null is undefined and object respectively

It is highly recommended to use === in the programming as we get very unexpected results out of ==. e.g.

false == 0   // true
false == "false&qu…