0% found this document useful (0 votes)
19 views

Assign 5

JavaScript is a programming language commonly used to add interactivity to web pages. It can modify HTML elements and respond to user input using event-driven programming. JavaScript uses asynchronous programming with callbacks, promises, and async/await to improve performance. Variables can have function or global scope, and prototypes allow flexible object creation.

Uploaded by

please read
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Assign 5

JavaScript is a programming language commonly used to add interactivity to web pages. It can modify HTML elements and respond to user input using event-driven programming. JavaScript uses asynchronous programming with callbacks, promises, and async/await to improve performance. Variables can have function or global scope, and prototypes allow flexible object creation.

Uploaded by

please read
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

JavaScript is a programming language that is commonly used for creating interactive effects within
web browsers. It is often used in conjunction with HTML and CSS to create dynamic web pages. Java,
on the other hand, is a separate programming language that is primarily used for building standalone
applications or for backend development. The purpose of JavaScript in web development is to add
interactivity to web pages by allowing developers to create functions that can respond to user
interactions, such as button clicks or form submissions.

2. JavaScript is used to manipulate the Document Object Model (DOM) which is the hierarchical
representation of an HTML document. HTML defines the structure of a web page while CSS defines
its style, while JavaScript allows for interaction with both the structure and style of the web page.
JavaScript can be used to modify HTML elements, add or remove elements, and change the styling of
elements.

3. Event-driven programming is a programming paradigm in which the flow of the program is


determined by events such as user actions or system events. In JavaScript, event-driven programming
is used to create interactive web pages that respond to user input. For example, a function can be
triggered when a user clicks on a button, or when a certain key is pressed on the keyboard.

4. The Document Object Model (DOM) is a programming interface for web documents. It represents
the page so that programs can change the document structure, style, and content. JavaScript can
interact with the DOM by accessing and manipulating elements, attributes, and properties of the
HTML document. This allows developers to create dynamic web pages that respond to user input.

5. Synchronous JavaScript executes code sequentially, blocking other code from running until the
current operation is completed. Asynchronous JavaScript allows code to execute in parallel, allowing
other code to run while waiting for an operation to complete.

6. JavaScript handles asynchronous programming using callbacks, promises, and async/await. These
approaches allow developers to write code that runs asynchronously, making web applications more
responsive and efficient. The benefits of asynchronous programming include better performance,
improved responsiveness, and the ability to handle large amounts of data. The challenges include
complexity, increased debugging time, and the potential for race conditions.

7. JavaScript uses function scope for variables, meaning that variables declared inside a function are
only accessible within that function. Variables declared outside of any function are considered global
variables, and can be accessed from anywhere in the code. Hoisting is a behaviour in which variables
declared with the var keyword are moved to the top of the function scope, allowing them to be
accessed before they are declared.
8. Closure is a programming concept that refers to the ability of a function to remember the variables
in its outer scope, even after the function has completed execution. This allows developers to create
functions that retain their state and can be used in a variety of different contexts.

9. Prototype-based inheritance is a type of inheritance used in JavaScript in which objects inherit


from other objects directly, rather than from classes. This allows for more flexible and dynamic
object creation, as objects can be created and modified at runtime.

10. Event Bubbling − Whenever an event happens on an element, the event handlers will first run on
it and then on its parent and finally all the way up to its other ancestors.

Event Capturing − It is the reverse of the event bubbling and here the event starts from the parent
element and then to its child element.

11. Null represents the intentional absence of any object value, while undefined is used to represent
a variable that has been declared but has not yet been assigned a value.

13. Dynamic typing in JavaScript means that a variable can hold different data types at different
points in time during the execution of the program. This differs from statically typed languages like
Java or C++, where variables must be declared with a specific data type and cannot be changed
during program execution.

16. Callbacks, promises, and async/await are all ways to manage asynchronous code in JavaScript.
Callbacks can lead to callback hell, where code becomes difficult to read and maintain. Promises
provide a cleaner way to handle asynchronous code, but can still be verbose. Async/await provides a
more concise and readable way to handle asynchronous code, but requires support for ES2017+.

17. "this" in JavaScript refers to the object that a function is a method of or the global object if the
function is not a method of any object. The value of "this" can change based on how a function is
called, such as with call(), apply(), or bind().

18. JavaScript engines optimize code by compiling code to bytecode and then to machine code, and
by using just-in-time (JIT) compilation to optimize frequently used code. Techniques to write
performant JavaScript code include minimizing object creation, using the appropriate data structure
for the task, avoiding unnecessary reflows and repaints, and minimizing DOM access.

19. JavaScript error handling can be managed with try-catch blocks, error objects, and by using tools
like the Chrome DevTools or Node.js debugging tools. Strategies for effective error handling include
logging errors, handling errors gracefully, and providing clear error messages to the user.
20. Common design patterns in JavaScript include the Module pattern, Revealing Module pattern,
Observer pattern, and the Factory pattern. These patterns can help make code more modular,
reusable, and easier to read and maintain.

21. Functional programming is a programming paradigm that emphasizes the use of functions as
first-class citizens, and avoids the use of side effects and mutable data. In JavaScript, functional
programming techniques can be used to write more modular and maintainable code by making use
of higher-order functions, closures, and immutability. Functional programming can also help with
concurrency and parallelism.

You might also like