Advance Js Interview Questions

Q2 In what ways we can empty a JavaScript Array?

Below techniques can be used to get an empty array:

  • You can modify the older array as an empty array.
  • You can fix the length according to you of a predefined array to zero.
  • You can update the array to contain zero elements with the help of the JavaScript splice() method.
  • You can pluck out all the elements of the array with the help of array methods: pop() or shift().
  • Or

    Q Explain the output of the following code.

    The output of the above-mentioned code is 5. It’s because the delete operator does not really affect the entire length of the array as the operates removes only the value which is there at the position. At the deleted index, we receive the value undefinedx1 (in Chrome) or just undefined/ empty. Therefore, if we have wished to try the statement console.log(courses),we will get (5) [“JavaScript”, “Java”, empty, “C++”, “Python”].

    Q2: Provide some examples of non-bulean value coercion to a boolean one

    The question is when a non-boolean value is coerced to a boolean, does it become true or false, respectively?

    The specific list of “falsy” values in JavaScript is as follows:

    Any value that’s not on this “falsy” list is “truthy.” Here are some examples of those:

    Q3 Can you remove the content from a website? If yes, then how?

    Yes, you will see some ways in which the content of a website can be easily removed at will. The simplest way is to hide the entire content from the browser you wish to remove. There is a display property of the JavaScript Style Attribute that assists us finish the job. Also, whenever we thing of adding any content to the webpage, its default display fixes to block (display: block). Moreover, we can easily modify the value to none (display: none). It will protect the content from being visible in the browser window. This whole approach only hide the details, you will still see it in the source code, and simply access it from the Elements window.

    There is one more way to do this by removing the element node corresponding the website content. This valuable technique entirely removes the data from your webpage along with the code. Also, we can do this by .removeChild() method. Or if we have to deal with an array (involving a NodeList), then we can simply empty that array, and receive the similar result. The final decision of choosing the correct method for the situation completely depends on the programmer and his/her requirements.

    Q19: What’s the difference between ES6 Map and WeakMap?

    They both behave differently when a object referenced by their keys/values gets deleted. Lets take the below example code:

    var map = new Map(); var weakmap = new WeakMap();

    The above IIFE is executed there is no way we can reference {x: 12} and {y: 12} anymore. Garbage collector goes ahead and deletes the key b pointer from “WeakMap” and also removes {y: 12} from memory. But in case of “Map”, the garbage collector doesn’t remove a pointer from “Map” and also doesn’t remove {x: 12} from memory.

    WeakMap allows garbage collector to do its task but not Map. With manually written maps, the array of keys would keep references to key objects, preventing them from being garbage collected. In native WeakMaps, references to key objects are held “weakly“, which means that they do not prevent garbage collection in case there would be no other reference to the object.

    Javascript Coding Interview Questions | Advanced Javascript Interview Questions

    Related Posts

    Leave a Reply

    Your email address will not be published. Required fields are marked *