1.What are the different datatypes are present in javascript?
Primitive-types:
- String
- Number
- BigInt
- Boolean
- Undefined
- Null
- typeof
Non Primitive-types:
- Object
Hoisting is a default behaviour of javascript where all the variable and function declarations are moved on top.
3.Difference between “ == “ and “ === “ operators
== This operator will compares the values.
=== This operator will compares the values and data types
4.Is javascript a statically typed or a dynamically typed language?
- NaN property represents “Not-a-Number” value. It indicates a value which is not a legal number.
- typeof of a NaN will return a Number .
- To check if a value is NaN, we use the isNaN() function,
6.Explain “this” keyword.
- The “this” keyword refers to the object that the function is a property of.
- The value of “this” keyword will always depend on the object that is invoking the function.
7.What is promises?
Promises are used to handle asynchronous operations in JavaScript. They are easy to manage when dealing with multiple asynchronous operations where callbacks can create callback hell leading to unmanageable code.
8. What is callback?
Callback is a function that is passed as an argument to an another function. A callback function can run after another function has finished
9.What is Call method?
This method invokes a method (function) by specifying the owner object. This will takes arguments separately.
10.What is apply method?
This is similar to call method. But this will takes arguments as an array
11.What is bind method?
- This is nothing but function borrow method.
- with the bind() method the object will borrow the function from other object
12.Explain Scope and Scope Chain in javascript.
Scope in JS, determines the accessibility of variables and functions at various parts in one’s code.
In general terms, the scope will let us know at a given part of
code, what are the variables and functions that we can or cannot access.
There are three types of scopes in JS:
- Global Scope
- Local or Function Scope
- Block Scope
Global Scope:
Variables or functions declared in the global namespace have global scope, which means all the variables and functions having global scope can be accessed from anywhere inside the code
Local or Function Scope:
Any variables or functions declared inside a function have local/function scope, which means that all the variables and functions declared inside a function, can be accessed from within the function and not outside of it.
Block Scope:
- Block scope is related to the variables declared using let and const. Variables declared with var do not have block scope.
- Block scope tells us that any variable declared inside a block { }, can be accessed only inside that block and cannot be accessed outside of it.
The syntax:
// works only inside async functions
let value = await promise;
The keyword await makes JavaScript wait until that promise settles and returns its result.
Here’s an example with a promise that resolves in 1 second:
async function f() {
let promise = new Promise((resolve, reject) => {
setTimeout(() => resolve("done!"), 1000)
});
let result = await promise; // wait until the promise resolves (*)
alert(result); // "done!"
}
f();
Closures is an ability of a function to remember the variables and functions that are declared in its outer scope.
- Introduced in ES6 version, generator functions are a special class of functions.
- They can be stopped midway and then continue from where it had stopped.
21.Name some of the built-in methods and the values returned by them.
Built-in Method | Values |
CharAt() | It returns the character at the specified index. |
Concat() | It joins two or more strings. |
forEach() | It calls a function for each element in the array. |
indexOf() | It returns the index within the calling String object of the first occurrence of the specified value. |
length() | It returns the length of the string. |
pop() | It removes the last element from an array and returns that element. |
push() | It adds one or more elements to the end of an array and returns the new length of the array. |
reverse() | It reverses the order of the elements of an array. |
22.What is the difference between Local storage & Session storage?
Local Storage – The data is not sent back to the server for every HTTP request (HTML, images, JavaScript, CSS, etc) – reducing the amount of traffic between client and server. It will stay until it is manually cleared through settings or program.
Session Storage – It is similar to local storage; the only difference is while data stored in local storage has no expiration time, data stored in session storage gets cleared when the page session ends. Session Storage will leave when the browser is closed.
23.What is the difference between undeclared & undefined?Undeclared variables are those that do not exist in a program and are not declared. If the program tries to read the value of an undeclared variable, then a runtime error is encountered. Undefined variables are those that are declared in the program but have not been given any value. If the program tries to read the value of an undefined variable, an undefined value is returned.
24.
Comments
Post a Comment