Js Useful Tips
Js Useful Tips
INTERVIEW GUIDE
]\
The let and const variables were introduced in JavaScript with the
ECMAScript 2015 (ES6) specification and both have Block-Level Scope.
var:
1
]\
let:
2
]\
const:
3
]\
Key Differences:
4
]\
2. Hoisting in JavaScript ?
Hoisting in JavaScript means that when you declare variables or
functions, JavaScript moves their declarations to the top of the scope
before the code actually runs. However, only the declarations are
hoisted, not the initializations.
5
]\
With let, each iteration of the loop has a separate i value, so the
setTimeout callback will log the correct i value for each iteration.
6
]\
7
]\
Template literals use backticks (`) instead of single quotes (') or double
quotes (").
The find method returns the first element in the array that
satisfies and The findIndex method returns the index of the first
element in the array that satisfies , If no elements satisfy the
condition, it returns -1.
8
]\
9
]\
Summary:
10
]\
1. Shorter Syntax:
2.this Binding:
11
]\
12
]\
7. Classes in JavaScript ?
JavaScript classes, introduced with ECMAScript 2015 (ES6), provide a
more structured and syntactically clearer way to create and manage
objects and inheritance compared to traditional constructor functions.
1. Class Declaration:
○ The class keyword is used to define a class.
○ A class body contains methods and a special method called
constructor.
2. Constructor Method:
○ The constructor method is a special method that is called when
an instance of the class is created.
13
]\
3 . Methods:
● Methods are defined inside the class body and its user defined function
is also called prototype function.
4 . Static Methods:
● Static methods are called on the class itself, not on instances of the
class. They are defined using the static keyword.
14
]\
5. Inheritance:
● Classes can extend other classes using the extends keyword. The
child class inherits methods and properties from the parent class.
15
]\
● Getters and setters allow you to define methods that get or set
the values of properties. They are defined using the get and set
keywords
16
]\
Summary.
17
]\
18
]\
1.Function Parameters:
In this example, the ...numbers parameter collects all the arguments passed
to the sum function into the numbers array.
19
]\
2. Destructuring Arrays:
3. Destructuring Objects:
20
]\
In this example, ...fruits spreads the elements of the fruits array into the
moreFruits array.
21
]\
7 . Promise in JavaScript ?
Key Concepts :
1. States of a Promise:
2.Promise Object:
22
]\
23
]\
Summary
24
]\
25
]\
Global functions are functions that are available globally, meaning they
can be accessed and invoked from anywhere in your code.
isFinite()
isNaN()
26
]\
10 . Generators in JavaScript ?
27
]\
when we copy one object to another object in this case object data is
not copied object reference is copied in this case we can used :
Shallow Copy :
A shallow copy creates a new object, but only copies the top-level
properties from the original object. Its work only single level .
28
]\
Deep Copy :
A deep copy creates a new object and recursively copies all properties and
nested objects from the original object.
29