15 General Interview Questions About JavaScript
This article provides you with a few general interview questions about JS to assist in your job search.
1. Mention a few advantages of using JavaScript?
Ans:
- Little interaction with servers: You can verify user feedback before sending the page to the server.
- Instant client response: They wouldn't have to wait to reload a page to check if they failed to type anything.
- Enhanced interactivity: You can build responsive interfaces when the user moves the mouse over them or triggers them with a keyboard.
2. Is JavaScript Case-Sensitive?
Ans: Yes, JavaScript is a case-sensitive language.
Eg: var Alert = "JS is a case-sensitive language"; function display() { document.writeln(alert);// this will result in an error. Here, Alert should be used } display();
3. Mention various Error Name values in JavaScript?
Ans:
- Eval Error
- Range Error
- Reference Error
- Syntax Error
- Type Error
- URI Error
4. What is Callback?
Ans: A callback is a simple JavaScript function passed as an argument or alternative to any method. It will be implemented after the execution of another process.
5. Explain how to read and write a file using JavaScript?
Ans:
- In JavaScript, readFile() function is used to read a file.
- In Javascript, the writeFile() function is used to write a file.
Syntax: writeFile( Path, Data, Callback)
6. How does TypeOf Operator work?
Ans: The TypeOf operator is used to get the operand's data type. An operand may be either a literal or a data structure, such as a vector, a method, or an entity.7. What are cookies in JavaScript?
Ans: A cookie is a collection of data that remains between the client-side and the server-side. A web browser holds this data during browsing.8. How to create a cookie using JavaScript?
Ans: The easiest way to create a cookie in JavaScript is by assigning a string value to the document.cookie object.Syntax: document.cookie = " key1 = value1; key2 = value2; expires = date";
9. Illustrate the difference between Attributes and Property?
Ans: Attributes - Gives more information on an entity such as id, type, etc.Property - It is the value that the entity is assigned to, such as type='text', value='Name', etc.