what is javascript:
javascript is an open source programing language. which help to create a dynamic web pages. it is also as browser language.
It can run on both the client-side (in browsers) and server-side (using environments like Node.js).
JavaScript supports event-driven, non-blocking, and asynchronous programming, which is essential for handling multiple tasks simultaneously.
varaible:
varaible are the container to store data
types of varaible
- var
- let
- const
operators:
Javascript operators are used to perform different types of mathematical and logical computations.
types of operators
- arithmetic = +,-,/,%,*
- comparison
- logical
data type
define the type of varaible
primitive data type = store the value by value
- String
- Number
- Bigint
- Boolean
- Undefined = we declare the variable, value is not defined. datatype is undefined
- Null = it is an assign value, we explicitly set the value as null. datatype is object
- Symbol
non premitive data type = store the value by reference(address)
- Object = Built-in object types can be: objects, arrays, dates, maps, sets, intarrays, floatarrays, promises
- example:
- null == undefined is true, but null === undefined is false.
The main difference between export and export default in JavaScript ?
is that export default is used to export a single value from a module,
while export with named exports is used to export multiple values
the main difference between primitive and non-primitive data types ?
- is that primitive types are predefined, while non-primitive types are created by the programmer.
- Primitive and Non-Primitive data structure that allows you to store only single data type values and to store multiple data type values. Primitive data types are stored directly in memory, whereas non-primitive data types are stored as references to their values in memory.
- primitive data types are passed by value and non-primitive data types are passed by reference.
- Primitive data types are immutable, meaning their values cannot be changed once assigned. Non-primitive data types are mutable and can be modified.
- Numbers, strings, and booleans are examples of primitive data types, while objects, arrays, and functions are examples of non-primitive data types.
function:
A JavaScript function is a block of code designed to perform a particular task.
Is javascript a statically typed or a dynamically typed language?
JavaScript is a dynamically typed language. In a dynamically typed language,
the type of a variable is checked during run-time in contrast to a statically typed language,
where the type of a variable is checked during compile-time.
Explain passed by value and passed by reference ?
In JavaScript, primitive data types are passed by value and non-primitive data types are passed by reference.
primitive data types
= string, number, boolean, null, undefined
non-primitive data types
= objects, arrays
What do you mean by strict mode in javascript and characteristics of javascript strict-mode ?
allows you to write a code or a function in a strict
operational environment.
As a result, debugging becomes a lot simpler.
What are factory functions in JavaScript ?
If we have complex logic, and we have to create multiple objects again and again that have the same logic,
we can write the logic once in a function and use that function as a factory to create our objects.
Itβs the same as a real-world factory producing products.
a factory function is a function that returns an object.
Higher Order Functions:
fuction take other fuction as an argument or return the function.
map, filter and reduce function are all example of HOF.
Higher-order functions are useful for tasks like event handling, data transformation (e.g., map and filter), and creating function factories or decorators.
Closures:
Closures are created when a function is defined inside another function,
and the inner function retains access to the variables and method in the outer function's scope
Closure provides a means to encapsulate data within functions, allowing for controlled access to that data while keeping it hidden from the outside scope.
callbacks:
Functions that are used as an argument to another function are called callback functions.
A callback is a function that will be executed after another function gets executed.
usecase of callback function when we want to perform asynchronous operation.
map() vs forEach()
map()
=> Iterates over each element of an array and applies a transformation function to each element.
Does not modify the original array; it creates a new array with transformed elements.
forEach()
=> Iterates over each element of an array and executes a provided callback function for each element.
Does not create a new array or modify the existing array; it only executes the callback function.
map() vs filter() vs reduce()
map()
it will return new array
filter()
it is similar to map() it also return new array but if the condition is true. used when we want to apply condition.
reduce()
it will return single value from an array.
this keyword:
The value of the this
keyword will always depend on the object that is invoking the function.
currying:
transform a function of n argument to n function.
usecase enabling partial application(when you have a function that takes multiple arguments, but you only want to fix some of them, while leaving others open for later use),
reuse of code.
e.g
function add (a) {
return function(b){
return a + b;
}
}
add(3)(4)
normal vs arrow function ?
normal function:
this refer to the object which call the function
can be use as a constructor
Function declarations are hoisted(allow hosting)
arrow function:
do not have their own this
cannot be use as a constructor
Function declarations are not hoisted(not allow hosting) // myfunc is not a function
normal and ternary condition ?
ternary condition store the refence without this context.
What is the difference between exec () and test () methods in javascript ?
test () and exec () are RegExp expression methods used in javascript.
some advantages of using External JavaScript?
We can reuse the code.
Code readability is simple in external javascript(code modularization)
prototype:
The JavaScript prototype property also allows you to add new properties and methods to objects constructors.
usecase for testing
memoization:
Memoization is a form of caching where the return value of a function is cached based on its parameters.
If the parameter of that function is not changed, the cached version of the function is returned.
DOM:
DOM stands for Document Object Model. DOM is a programming interface for HTML.
When the browser tries to render an HTML document, it create a DOM
Using this DOM, we can manipulate or change various elements inside the HTML document.
BOM:
Browser Object Model is known as BOM. It allows users to interact with the browser.
A browser's initial object is a window.
Promises:
Promises are used to handle asynchronous operations in javascript. Before promises, callbacks were used to handle asynchronous operations.
Promise object has four states -
Pending
- Initial state of promise.
Fulfilled
- This state represents that the promise has been fulfilled,.
Rejected
- This state represents that the promise has been rejected.
Settled
- This state represents that the promise has been either rejected or fulfilled.
async/await:
it is built on top of promises, it provide more consise way to write async code, making it easier to read and write.
async keyword is used to declare synction function and await is used to wait for promises to be resolved.
express vs structure
=>express is which return some value
e.g
const x=5;
const y=myfun();
5 and myfun()
return some value is an expression
statement which instruct and order action, but does not return value
e.g.if,else,
while are those are statement
while(i<2){}
rest parameter and spread operator:
rest parameter it combined the separate element into an array
spread operator is used to seperate array into single element
generator functions ?
They can be stopped midway and then continue from where they had stopped.
The generator object consists of a method called next(), this method when called, executes the code until the nearest yield statement, and returns the yield value.
call(),apply() and bind():
all these are use to assing object to this keyword(assign value to this keyword)
usecase when we want to manipulate this keyword of a fuction with desired object
The bind() method
creates a new function that, when called, has its this keyword set to the provided value(e.g object). it create a new object.
call() and apply()
serve the exact same purpose. The call() method does not make a copy of the function it is being called on.
The only difference between how they work is that call() expects all parameters to be passed in individually,
whereas apply() expects an array of all of our parameters.
IIFE:
immediately invoked function that run as soon as it defined.
e.g.
(function(){
// Do something;
})();
pure function:
produce same output for same input. It takes place when the operands of an expression are of different data types.
function which does not modify the external state or varaible
Is javascript a statically typed or a dynamically typed language?
In a dynamically typed language, the type of a variable is checked during run-time in contrast to a statically typed language,
where the type of a variable is checked during compile-time.
e.g.
static type
string name="salman";
// varaible has types
dynamic type
var name="salman";
// convert into string at runtime
coercoin:
the automatic conversion of value from one data type to another.
String coercion
+
convert the number into string
-
convert string into number
NaN():
isNaN() function converts the given value to a Number type, and then equates to NaN.
ASP script v/s javascript ?
ASP script runs on the server, while JavaScript runs on the client's browser.
ASP script is a server-side language used for handling complex tasks, such as database queries, form submissions, and user authentication.
while JavaScript is a client-side language used for creating interactive elements on web pages, such as animations, pop-up windows, and form validation.
Undefined Value:
value is not defined but variable is present
missing property in an object
eslint:
it help to debug and fine common vulnerablity in javascript code
want to know more about me, just write sallbro on search engine...
Top comments (0)