Found 6685 Articles for Javascript

What is the difference between void, eval, and the Function constructor in JavaScript?

usharani
Updated on 16-Jun-2020 13:12:48

208 Views

The void keywordThe void is an important keyword in JavaScript, which can be used as a unary operator that appears before its single operand, which may be of any type. This operator specifies an expression to be evaluated without returning a value.The syntax of the void can be either of the following two −               The eval() functionThe JavaScript eval() is used to execute an argument. The code gets execute slower when the eval() method is used. It also has security implementations since it has a different scope of execution.ExampleHere’s how you can ... Read More

How to make an anchor tag refer to nothing?

varun
Updated on 16-Jun-2020 13:10:42

4K+ Views

To make an anchor tag refer to nothing, use “javascript: void(0)”. The following link does nothing because the expression "0" has no effect in JavaScript. Here the expression "0" is evaluated, but it is not loaded back into the current document.ExampleLive Demo                                         Click the following, This won't react at all...       Click me!      

What is the difference between JavaScript undefined and void(0)?

Prabhas
Updated on 16-Jun-2020 13:09:36

372 Views

JavaScript undefinedIt means a variable declared, but no value has been assigned a value.For example, var demo; alert(demo); //shows undefined  alert(type of demo); //shows undefinedHere’s another example showing the usage of undefined to check whether a variable exists or not:ExampleLive Demo                    var age = 10;          if( typeof age !== 'undefined' ) {             document.write("True");          } else{             document.write("False");          }           OutputTrueJavaScript void(0)The void ... Read More

How to use void keyword in JavaScript?

Shubham Vora
Updated on 31-Oct-2022 11:01:31

182 Views

In this tutorial, let us discuss how to use the void keyword in JavaScript. We use the void keyword as the return type of function that does not return any value. It evaluates an expression and returns undefined. We can use this with a single operand because this is a unary operator. We should not wrap the expression in parentheses because void is not a function. void 0 is the same as void(0). Users can follow the syntax blocks to deal with each use case. Syntax void expression The expression can be a variable or a function. Use void ... Read More

How to call JavaScript function in an alert box?

Saurabh Jaiswal
Updated on 05-Apr-2023 10:59:07

5K+ Views

To call a JavaScript function in an alert box, you can use the alert() function, a built-in function in JavaScript that displays an alert dialog with a specified message. An alert box is a simple dialog box that displays a message to the user and provides an OK button. It is a built-in function in JavaScript that is often used for debugging or displaying simple notifications to the user. Here's an example of how to use the alert() function in JavaScript − alert("Hello, World!"); // displays an alert box with the message "Hello, World!" The alert() function takes a ... Read More

How to center the JavaScript alert message box?

Shubham Vora
Updated on 02-Aug-2022 13:46:53

9K+ Views

In this tutorial, we will learn to center the JavaScript alert box. In JavaScript, an alert box is useful to show users some message, information, warning, success, etc. Let’s understand it by real-world example when you open any website on the web browser and start to authenticate by entering your username and password. When you click the submit button, it gives a message in an alert box like the password should of be 8 or more characters, or sign in successfully. Users can create the alert box using JavaScript's alert() method. Unfortunately, the default alert box doesn’t allow us to ... Read More

How to customize the position of an alert box using JavaScript?

mkotla
Updated on 16-Jun-2020 12:45:56

2K+ Views

To customize the position of an alert box, use the CSS “top” and “left” properties. We have a custom alert box, which we’ve created using jQuery and styled with CSS.ExampleYou can try to run the following code to customize the position of an alert box −Live Demo                          function functionAlert(msg, myYes) {             var confirmBox = $("#confirm");             confirmBox.find(".message").text(msg);             confirmBox.find(".yes").unbind().click(function() {                confirmBox.hide();   ... Read More

How I can show JavaScript alert box in the middle of the screen?

Giri Raju
Updated on 25-Sep-2019 08:53:43

1K+ Views

To show the JavaScript alert box in the middle, you need to use the custom alert box. Under that, style it accordingly and position it to the center. Use the “top” and “left” CSS properties to achieve this. Set them as 50%, but as you can see a button below, use the property to 40% to align it with the button:ExampleLive Demo                          function functionAlert(msg, myYes) {             var confirmBox = $("#confirm");             confirmBox.find(".message").text(msg);     ... Read More

How I can set the width and height of a JavaScript alert box?

Nishtha Thakur
Updated on 16-Jun-2020 13:38:12

3K+ Views

To set the width and height of an alert box in JavaScript, you need to use the custom alert box. This alert box is styled with CSS.Set the width and height of the alert box using the following code, which uses jQuery, a JavaScript library −Example                                function functionAlert(msg, myYes)          {             var confirmBox = $("#confirm");             confirmBox.find(".message").text(msg);             confirmBox.find(".yes").unbind().click(function()       ... Read More

How do I check if an array includes an object in JavaScript?

Shubham Vora
Updated on 20-Jul-2022 08:01:11

5K+ Views

In this tutorial, we will learn to check whether an array includes an object or not. The actual array contains the values with the same data types. In JavaScript, the array is replaced with the list, including values with any data type even if users can add the objects inside the list with numbers and strings.So, programmers sometimes need to figure out if the array contains the objects or not. Programmers can access the object properties and perform some operations if the array contains an object.Here, we have different methods to check whether the array contains an object.Using the array.includes() ... Read More

Advertisements