Found 8895 Articles for Front End Technology

How to test a value x against predicate function and returns fn(x) or x in JavaScript?

Mohit Panchasara
Updated on 09-Mar-2023 12:45:01

63 Views

Testing the value x against the predicate function means checking if x is evaluated to be valid for a particular condition. If x is following the particular condition, we need to perform some operation on the x using any function named ‘fn’ and passing it as a function parameter. Otherwise, we need to return the value of x itself. Syntax Users can follow the syntax below to test a value x against the predicate function and return the fn(x) or x in JavaScript. let result = predicate(x) ? operation(x) : x; In the above syntax, we ... Read More

How to terminate a script in JavaScript?

Mohit Panchasara
Updated on 09-Mar-2023 12:32:39

12K+ Views

The termination of the script means that it stops executing the JavaScript code. In some emergency cases, developers requires to abort the execution of JavaScript code in the middle while the script is executing. Also, we can use the if-else statement to decide when to terminate the script execution and when to continue. Here, we will learn different ways to terminate the script midway. Use the Return Statement The return statement is used to terminate the execution of any code inside the script. Once we execute the return statement inside the function, the code written after the return statement ... Read More

How to stop event propagation with inline onclick attribute in JavaScript?

Mohit Panchasara
Updated on 09-Mar-2023 12:22:53

2K+ Views

Sometimes, we require adding the same events on the nested HTML elements. For example, we have two divs, one is parent div, and another is child div. Now, we need to add the onclick event on the parent div and child div and execute the different functions when users click on the parent div and child div. In this case, it will always execute the event on the parent div and child div. Let’s understand executing the same event on the nested HTML elements via the example below. Example In the example below, we have created the two ... Read More

Identifiers and Keywords in Typescript

Rushi Javiya
Updated on 07-Mar-2023 12:37:57

2K+ Views

In this tutorial, we'll learn about identifiers and keywords in TypeScript. Identifiers and keywords are two fundamental concepts in TypeScript, a statically-typed superset of JavaScript. Identifiers are names we give to variables, functions, classes, and other things in our code. Keywords are special words with specific meanings in TypeScript and can't be used as identifiers. Identifiers must follow certain rules in naming variables, functions, and classes to avoid syntax errors. On the other hand, using keywords as identifiers can lead to errors and make our code difficult to read and understand. Rules and Best Practices for Identifiers and ... Read More

How to use SolverJS?

Rushi Javiya
Updated on 07-Mar-2023 12:35:30

92 Views

SolverJS is a comprehensive JavaScript package that provides a range of functions to help us solve common math problems. We know that web applications often require complex logic to function properly, and these logical solutions can easily become long and difficult to manage. This is where Solver JS comes in - it includes a wide range of general and complex mathematical solutions and provides functions not available in standard JavaScript. In this tutorial, we will learn how to use Solver JS and its various functions. The package includes functions such as date conversions, keyword extraction, string case checking, URL ... Read More

How to use Ejs in JavaScript?

Rushi Javiya
Updated on 07-Mar-2023 12:33:21

6K+ Views

EJS is a templating language that allows us to generate HTML markup using plain JavaScript. It provides a simple and intuitive way to generate dynamic content in our web applications, making it easier to manage and organize our code. EJS is easy to use and can be integrated into any JavaScript project with just a few steps. In this tutorial, we will learn the basics of how to use EJS in JavaScript, including how to set up our project, create an EJS template, and render the template to generate dynamic HTML output Steps to use EJS in a JavaScript ... Read More

How to check whether image is loaded or not?

Aman Gupta
Updated on 07-Mar-2023 11:52:34

9K+ Views

Overview To check for an image whether it is loaded or not in order to perform some actions can be done by using JavaScript. In many cases our browser fails to load the image due to large size of image, or poor network connectivity. So our image may sometimes show some errors. So to know whether our image is loaded or not we have certain methods such as onload(), onerror() and complete property. Syntax The syntax to solve the problem are − onload="function()" − This function is called when the image is loaded successfully. In this any callback function ... Read More

How to check the given element has the specified class in JavaScript?

Aman Gupta
Updated on 07-Mar-2023 11:45:20

760 Views

Overview To perform a certain task first we need to access that particular element by its class or by id so before accessing the element we check whether that class is present in that particular element or not. The classList object contains the built-in method classList.contains() in JavScript. This method determines whether the given element belongs to the specified class. This whole process will take place, as first we have to access that element by getElementById(), getElementsByClassName(), or any other method. After accessing it, we have to check for the class with the classList.contains() method. Syntax The syntax used in ... Read More

How to share code between Node.js and the browser?

Rushi Javiya
Updated on 07-Mar-2023 12:06:04

1K+ Views

Sharing code between the backend and front end of a full-stack application can be a challenging task. However, it's essential for building maintainable and scalable applications. By sharing code, we can avoid code duplication, reduce development time, and maintain consistency across our applications. In this tutorial, we'll explore different techniques for sharing code between Node.js and the browser and learn how to choose the best approach for our project. Techniques for Sharing Code Between Node.js and the Browser Users can follow the approaches below to share code between node.js and the browser − CommonJS Modules CommonJS modules are ... Read More

Check for the existence of key in an object using AngularJS

Aman Gupta
Updated on 07-Mar-2023 11:41:05

2K+ Views

Overview The existence of a key in an object can be checked using AngularJS. The key in an object is unique and cannot be duplicated. As object is a collection of different data types in Key-Value form, which contains String, Number type of data into a single reference variable. To check the existence of a key, we will use the "in" operator, which will check the object and return true or false. Syntax The syntax used in this problem is − if (key in objectName ) { action } else { action } ... Read More

Advertisements