All About Javascript For Intermediate
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
function add (a) { return function(b){ return a + b; } } add(3)(4)
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.
const x=5; const y=myfun();
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
(function(){ // Do something; })();
dynamic type
string name="salman"; // varaible has types
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...
The above is the detailed content of All About Javascript For Intermediate. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.

C and C play a vital role in the JavaScript engine, mainly used to implement interpreters and JIT compilers. 1) C is used to parse JavaScript source code and generate an abstract syntax tree. 2) C is responsible for generating and executing bytecode. 3) C implements the JIT compiler, optimizes and compiles hot-spot code at runtime, and significantly improves the execution efficiency of JavaScript.
