To 10 JavaScript interview Question and solution

1.This
If a method or function contains “this”, then “this” will represent the object from which the method or function will be called.

In a method, this refers to the owner object.

2.Encapsulation
Encapsulation does not hide data at all, it is just a security wrapper on the data. To set the data using the setter method and to get the data using the getter method

3. JavaScript Closures
Closure is a function with some remember values. A Closure gives you access to an outer function scope from an inner function.

4.prototype
A prototype is the property of any function in JavaScript that points to an object. The prototype works as an inheritance.
5.Call/Apply/Bind
We can use the method or function of one object in another object through call, apply and bind.
note: bind return a function but call and apply doesn’t return.
first image… applying method of an object. the second image.. use this method from another object.



6. Truthy and Falsy
A falsy value is something that evaluates to FALSE, for instance when checking a variable. There are only six falsy values in JavaScript: undefined
, null
, NaN
, 0
, ""
(empty string), and false
of course.
example :


7. Null Vs Undefined
In JavaScript, undefined is a type, whereas null an object. It means a variable declared, but no value has been assigned a value. Whereas, null in JavaScript is an assignment value.

8. Double equal (==) vs Triple equal (===)
The double equal only check value is equal or not but the triple check value and data type is equal or not.
example:


9.Count the number of words in a string
solution:

10.Remove duplicate item from an array
solution:

11.Find Factorial on Recursive Method
solution:
