JavaScript Interview Questions
1 .
Explain export & import in JavaScript?
The export statement is used when creating modules for JavaScript to export functions, primitive values or objects from the blades so they can be used by the programs with import statement which works opposite to it.
 
The import statement is used when we import buildings which are exported by another module. All imported modules are in strict mode. This statement can’t be used in embedded scripts.
2 .
How can you do a character count in Javascript?
To perform a character count in JavaScript, use the following syntax:
 
var str = "Hello World!";

var n = str.length;
3 .
What is the method to change the title of a page using JavaScript?
Generally, the page title varies based on the HTML document and the element structure. We can give id to an element and use code:
 
document.getElementById(‘page-title-id’).innerHTML=NewTitle;
4 .
Can you redirect a page to another page using JavaScript? How?
Yes, it is possible to redirect a page to another page or URL using JavaScript by using location, replace, and location.assign.
5 .
What you mean by Hoisting in JS?
The concept of hoisting stands for uplifting the variable and functions on the top of their scope before the code execution takes place. In the JavaScript mechanism, no matter wherever the functions are declared, they are taken on the topmost position, immaterial of their scope (global or local).
6 .
How can you submit a form using JS?
To submit a simple form, the below code will work.
 
document.form[0].submit();
7 .
What is BOM in JS?
BOM stands for Browser Object Model, a more extensive representation of elements provided by the browser like document, location, history, and frames exposed to JavaScript. DOM is a part of BOM, and to access the document, one can use code document or window.document.
8 .
Please list some of the Design Patterns in JS.
Whenever somebody wants to reuse solutions for regularly occurring problems in software designing, Design Patterns will solve the purpose.
 
Latest Design Patterns in JS are :
 
* Module Design pattern
* Revealing Module pattern
* Prototype Design pattern
* Revealing Prototype pattern
* Observer Design pattern
* Singleton
9 .
Deep vs. shallow object copying in JavaScript.
Deep Coping : This means that all the values of the existing/original variables are copied to a new variable, and thus, disconnected from the existing variables.

Shallow Coping : When commanded for shallow coping, not all the existing variables are disconnected, and some of the values or sub-values are still connected to the original.
10 .
How to formulate a cookie using JS?
A cookie is a set of data saved on the computer and accessed by the browser.
 
Step to create a JavaScript cookie :
 
document.cookie = “cookiename=Ftl”; expires = date”;