1. Set vs Map in JavaScript ? Set In JavaScript,? Set is a new object type that is used to create collections of unique values. These values are either primitives like strings or integers as well as more complex object types like object literals or arrays. The Set object lets you store unique values of any type. Set objects can be iterated in the insertion order. A value in the Set may only occur once. It is unique in the set’s collection.
Methods:
Set.prototype.add(): It adds the new element with a specified value at the end.
Set.prototype.delete(): It deletes an element with the specified value from the Set object.
Set.prototype.values(): It returns all the values in the insertion order.
Set.prototype.keys(): It also returns all the values like Values() method in the insertion order.
Map in JavaScript?
In JS, ES6 provides a new collection type called map. The Map is a collection of keyed data items, just like an Object. The Map allows keys of any type objects or primitive. The Map object holds key-value pairs and remembers the original insertion order of the keys. Any object or primitive values may be used as either a key or a value. A Map object iterates its elements in insertion order.
Methods:
new Map() – creates the map.
map.set(key, value) – stores the value by the key.
map.get(key) – returns the value by the key, undefined if key doesn’t exist in map.
map.delete(key) – removes the value by the key.
map.size – returns the current element count.
2. Is JavaScript a case-sensitive language ?
Yes, JavaScript is a case sensitive language. All JavaScript identifiers are case sensitive. The language keywords, variables, function names, and any other identifiers must always be typed with a consistent capitalization of letters. For example: The variables Name and name, are two different variables.
What is a service worker in JavaScript ?
A Service Worker is a JavaScript file that runs in the browser background, separate from a web page and act as proxies between web browsers and web servers. Programmatically managing a cache of responses. Major features of service workers are Rich offline experiences, periodic background syncs, push notifications and handle network requests.
4. What is Callback Function in JavaScript ?
Callback is a function passed into another function as an argument, which is invoked inside the outer function to complete some kind of actions. The callback function can run after another function has finished and functions are executed in the sequence they are called. Not in the sequence they are defined. The JavaScript functions are objects. We Can also pass objects to functions as parameters.
5. What is Closure in JavaScript ?
A closure is a function it gives access to an outer function’s scope from an inner function. This applies even when the execution of the outer function has already finished. Closure is used to hide the implementation details and showing only functionality to the end user in JavaScript. In other words, it can be useful to create private variables or functions. A closure is the combined feature of the functional bundled with references to the lexical environment.
6. Double equals == VS Triple equals === in JavaScript ?
What is == double equals operator in JavaScript?
The double equals == is Known as the equality operator that checks whether its two operands are equal or not and it returns a result.
So, when you compare string with a number, the JavaScript converts any string to a number. An empty string is always converts to zero
and also string with no numeric value is converts to NaN (Not a Number) which returns false.
What is === triple equals operator in JavaScript?
The === triple equals is called identity or strict comparison operator. The === operator checks both the value and the type of two operands whether the two operands are equal or not and return a true or false value.
The === triple equals operator returns false when the values are not similar type and returns true when they are similar type.It supports typecasting, for example, let’s compare 1===”1” this will return false as the values are the same but the type is not the same that means 1 = integer and “1” = String both are not same.
Double equals == VS Triple equals === in JavaScript?
Both double equals == and triple equals === operator is used for comparing between two values.
The double equals operator “==” compares only content whereas The triple equals “===” operator compares both content and type. JavaScript counts anything that is in between the two “quotation marks” as a string.
7. What is negative Infinity in JavaScript ?
The Negative Infinity is a number in JavaScript which can be derived by dividing negative number by zero. The negative infinity is a constant value which is used to represent a value. The value of negative infinity is the same as the negative value of the infinity property of the global object.
8. What would be the result of 7+2+”9″ in JavaScript ?
Here 7 and 2 are integers, they will be added numerically. And here 9 is a string, its concatenation will be done. So the result would be 99.
9. What is the use of isNaN function in JavaScript ?
The isNaN() function is used to check whether a given value is a number or not.
If the argument is not a number, the isNan() function returns true otherwise false.
10. What is a prompt box in JavaScript ?
A prompt box is a box that allows the user to enter input by providing a text box. It is used to take the input from the user. A label and box will be provided to enter the text or number. It contains two buttons OK and Cancel. If the user clicks “OK” the box returns the input value otherwise the user clicks “Cancel” the box returns null.
11. Differences between undeclared and undefined variables in JavaScript ?
Undeclared: Simply undeclared is a variable. It occurs when we try to access any variable that is not declared earlier using var, let or const keyword. Undeclared variables is always global. If we use ‘typeof’ operator to get the value of an undeclared variable, we will face the runtime error with the return value (undefined).
Undefined: Undefined is not a keyword. It occurs when a variable has been declared but has not been assigned any value not declared.
12. What is a prototype chain in JavaScript ?
In JavaScript, Every object in JavaScript has a built-in property, which is called its prototype.
Prototype chaining is used to build new types of objects based on existing ones. The prototype is itself an object, so the prototype will have its own prototype. so it is called prototype chain. The chain ends when we reach a prototype that has null for its own prototype. It is similar to inheritance in a class based language.
13. What is the difference between slice and splice in JavaScript ?
Slice: The slice() array method can be used to copy arrays but not passing any arguments
It Doesn’t modify the original array(immutable)
It Returns the subset of original array
It Gives part of array & NO splitting original array
It Used to pick the elements from array
Splice: The methods mutate an array by either adding to the array or removing from an array.
It is Used to insert or delete elements to/from array
It Modifies the original array(mutable)
It Returns the deleted elements as array
It Gives part of array & Splitting original array
14. What are modules in JavaScript ?
Modules refer to small units of independent, reusable code and also act as the foundation of many JavaScript design patterns. A module may contain a class or a library of functions for a specific purpose. Most of the JavaScript modules export an object literal, function or a constructor.
Why do you need modules:
Maintainability
Reusability
Namespacing
15. Difference between Let and Const in JavaScript ?
In JavaScript, Let and Const are almost same but only difference is that once you assigned a value to const, you cannot change the value because it is a constant variable. Whereas let can be assigned or re-assigned, but variables declared with const can’t be re-assigned. Let allows you to declare variables that are limited to the scope of a block statement, or expression and declares the variables globally or locally to an entire function. Before ES2015, JavaScript had only two types of scopes Global Scope and Local Scope. After ES2015, JavaScript was introduced Let and Const Keywords.
Global Scope: The Variables are declared outside any function is called Global Scope. The Global variables can be accessed from anywhere in a JavaScript program.
Local Scope: The Variables are declared inside a function is called Local Scope. The Local variables can only be accessed from inside the function only.
“let” keyword in JavaScript: In JavaScript, let is a keyword it is used to declare a block scoped variables. You can use assigned or re-assign the variables.
“Const” keyword in JavaScript: In JavaScript, Const is a keyword it is used to declare a block scoped variables. You cannot be re-assign the variables.
16. What is scope in JavaScript ?
In javascript, Scope is the accessibility of functions, objects and variables in some particular part of your code. In other words, Scope refers to the part of a program where we can access a variable and scope determines the visibility of variables.
There two types of scopes local and global:
Local variables are those declared inside of a block.
Global variables are those declared outside of a block.
17. What is IndexedDB in JavaScript ?
IndexedDB is a low-level API for client-side storage of larger amounts of structured data, It is an API used to store data inside the user’s browser. The indexedDB is more powerful than local storage. An IndexedDB database contains one or more object stores.
18. How do you check web storage browser support ?
First of all You need to check browser support for localStorage and sessionStorage before using web storage like.
if (typeof Storage !== “undefined”) {
// Code for localStorage/sessionStorage.
} else {
// Sorry! No Web Storage support..
}
19. What is web storage ?
Web storage is an API in JavaScript, The web storage is more secure and large amounts of data can be stored locally on the client-side web browser. It can store key/value pairs locally within the user’s browser. The web storage provides two mechanisms for storing data on the client.
Local storage: It stores data for current origin with no expiration date.
Session storage: It stores data for one session and the data is lost when the browser tab is closed.
20. What is JSON ?
JSON stands for JavaScript Object Notation. It is a lightweight text-based format for storing and exchanging data in a way that’s both human-readable and machine also. It is used for transferring data between a server and a web application. It is based on a subset of JavaScript language in the way objects are built in JavaScript.
*Disclaimer: We have published the above images and information for reference purpose only, for any changes on the content we refer to visit the Official Website to get the latest info.
NOTE: Walkinsbook.com Employees will not call any candidates towards Job Offer or Job assistance. We never charge any candidates for Jobs. Please be aware of fraudulent Calls or Emails.