1. What are the differences between general functions and arrow functions?
Kindly refer to this
2. Explain JavaScript Functions?
A JavaScript Function is a block of code designed to perform a particular task. A JavaScript function is executed when something invokes it (calls it).
We can define the code once, and use it many times. We can use the same code many times with different arguments, to produce different results (We can reuse code ).
Example:
3. What are the different types of JavaScript Functions?
- Function declaration (regular function)
- Function expression
- Shorthand method definition
- Arrow function
- Generator function
4. What is a Factory Function?
A Factory function is any function that returns a new object for every function call. The Function name should follow the camelCase naming convention.
Syntax:
5. What is a Constructor Function?
The Constructor Function is used to create Objects.
It is a regular function that returns a new object on calling with the
Syntax:
When a function is called with the
- Creates an empty object and assigns it to this
- Return this
Example:
6. What function is called when two functions have the same name?
The last function is called.
When we define the multiple functions with the same name, then the last defined one will be called. It is called Function Overriding.
JavaScript supports Function Overriding.
7. What is a regular function?
A Regular function is nothing but the Function Declaration.
It is defined by a
Example:
8. Name any four client-side storages?
Client-Side Data Storage is storing the data on the client (user's machine).
- Local Storage
- Session Storage
- Cookies
- IndexedDB and many more.
9. What is the size of localStorage?
LocalStorage is limited to about 5MB and can contain only strings.
10. What is local storage and its methods?
The Local Storage allows web applications to store data locally within the user's browser. It is a Storage Object. Data can be stored in the form of key-value pairs.
Methods:
setItem(): The
Syntax:
getItem(): The
Syntax:
removeItem(): The
Syntax:
11. Whether the Local Storage values will be deleted if we clear the cache in Browser?
No, the Local Storage values won't be deleted if we clear the cache.
Local Storage values will be deleted,
- When removed the particular key value using the localStorage.removeItemmethod
- When removed the whole Local Storage values using the localStorage.clearmethod
- When cleared the recent history with the cookies from start time in Browser.
12. How do you know the Cookie has expired?
While using the
We can know the Cookie has expired, if the
Example:
13. How do you find the present date and time?
We can find the present date and time by using
We can create a date object without passing any arguments to the
Example:
Here, the
14. Name some of the built-in methods in JavaScript?
some of the built-in methods in JavaScript:
Name | Description |
---|---|
ceil() | Returns the smallest integer that is greater than or equal to the given number |
concat() | Combines two strings and returns the newer string |
constructor() | Returns the function that created the corresponding instance of the object |
Date() | Returns the present date and time |
pop() | Removes and returns the last element from an array |
slice() | Returns the selected elements in an array, as a new array. |
15. What is an arrow function?
An Arrow function is a simple and concise syntax for defining functions.
It is an alternative to a function expression.
Syntax:
Example:
16. What are the uses of Arrow Functions?
An Arrow function is a simple and concise syntax for defining functions.
- It is an alternative to a function expression.
- It inherits thisfrom the context in which the code is defined.
- The returnstatement and curly braces are not required for simple expressions.
- If there is only one parameter, then parentheses are not required.