JavaScript Viva
JavaScript Viva
an interview or assessment:
11. **What is an arrow function, and how is it different from a regular function?**
- **Answer:** Arrow functions are a shorter syntax for writing functions. They do not have their
own `this`, arguments, super, or new.target bindings, making them unsuitable for methods.
26. **What is the difference between synchronous and asynchronous code in JavaScript?**
- **Answer:** Synchronous code is executed in sequence, blocking the execution of
subsequent code until the current task is completed. Asynchronous code allows multiple tasks
to be executed concurrently, with tasks being delegated to the browser or Node.js to handle and
continue processing other tasks.
32. **What is the difference between `Object.create()` and using a constructor function for
creating objects?**
- **Answer:** `Object.create()` creates a new object with the specified prototype object and
properties, while a constructor function is used to create an instance of an object with `new`.
34. **What is the difference between function declarations and function expressions?**
- **Answer:** Function declarations are hoisted and can be used before they are defined.
Function expressions are not hoisted and can only be used after they are defined.