Found 10483 Articles for Web Development

How exactly does

Why in JavaScript, “if ('0' == false)” is equal to false whereas it gives true in “if(0)” statement?

mkotla
Updated on 16-Jun-2020 13:28:37

2K+ Views

Let’s see the conditions one by one − if(‘0’ == false)It follows the following rule −If Type(y) is Boolean, return the result of the comparison x == ToNumber(y)The == does type coercion. This means an explicit type conversion is requested to match the type of the two operands. The left side '0' is converted to a number 0. On comparing the two numbers, and since 0 equals 0, the result is true. In this case, this does not work since it does not implies about the truish/falsy nature of the '0' string, since it got coerced before it was compared.if(0)This checks ... Read More

How to print current year in JavaScript?

Giri Raju
Updated on 16-Jun-2020 13:27:38

1K+ Views

To get current year in JavaScript, use the getFullYear() method.ExampleYou can try to run the following code to print current year −Live Demo           Click below to get the current year:       Display Year                      function display() {             var date = new Date();             var res = date.getFullYear();             document.getElementById("test").innerHTML = res;          }          

How to print object array in JavaScript?

Shubham Vora
Updated on 15-Sep-2022 12:34:19

21K+ Views

In this tutorial, we will learn how to print object arrays in JavaScript. What is an object array or an array of objects? An array of objects is used to store a fixed-size sequential collection of identical elements and store many values in one variable. Next, we will see the options to print an array of objects in JavaScript. Using the stringify() Method of the JSON Object Here, we will learn how to stringify the object array. To correctly display an array of objects, we need to format the array as a JSON string. JSON.stringify() formats the array and gives ... Read More

How to get current date and time in JavaScript?

varma
Updated on 16-Jun-2020 13:25:45

478 Views

To get current date and time in JavaScript, use the Date object.ExampleYou can try to run the following code to display date and time −                          document.getElementById("currentDate").innerHTML = Date();          

How to use “window.print()” function to print a page?

usharani
Updated on 16-Jun-2020 13:25:14

1K+ Views

To print a page in JavaScript, use the window.print() method. It opens up the standard dialog box, through which you can easily set the printing options like which printer to select for printing.ExampleYou can try to run the following code to learn how to print a page −Live Demo           Click to Print                function display() {             window.print();          }          

How to create JavaScript alert with 3 buttons (Yes, No and Cancel)?

Prabhas
Updated on 10-Jan-2020 10:30:53

4K+ Views

The standard JavaScript alert box won’t work if you want to customize it. For that, we have a custom alert box, which we’re creating using jQuery and styled with CSS.ExampleYou can try to run the following code to create an alert box with 3 buttons i.e Yes, No and Cancel.                          function functionConfirm(msg, myYes, myNo, cancel) {             var confirmBox = $("#confirm");             confirmBox.find(".message").text(msg);             confirmBox.find(".yes, .no, .cancel").unbind().click(function() {     ... Read More

How to check if a variable is an integer in JavaScript?

Shubham Vora
Updated on 08-Aug-2022 08:44:08

6K+ Views

In this tutorial, we will learn to check if a variable is an integer in JavaScript. Before we solve the problem, we must have a problem. We can ask ourselves, “why do we need to check if the variable is an integer?”. Let’s understand the answer using a single example. Suppose, we are taking the value from the user using the input text box. It returns the values in the string format, and now think that we are adding values. Will we get the correct result? Obviously, not. So, in such cases, we need to check if the variable is ... Read More

How to create and apply CSS to JavaScript Alert box?

Arpit Anand
Updated on 16-Jun-2020 13:17:23

8K+ Views

 The standard alert box in JavaScript does not provide the option to apply CSS. To style your alert box, you need to create a custom one first. The custom alert box will be created using jQuery and styles will be applied to CSS.ExampleYou can try to run the following code to learn how to create and apply CSS to alert box −Live Demo                          function functionAlert(msg, myYes) {             var confirmBox = $("#confirm");             confirmBox.find(".message").text(msg);   ... Read More

Advertisements