Found 6710 Articles for Javascript

How to Validate your Website Code?

Rahul Sharma
Updated on 04-Oct-2019 12:20:03

287 Views

Website development included writing code in HTML, CSS, JavaScript and the platform you’ve chosen. Your website may look correct, responsive and developed with website standards, but it may have some internal issues.Tools are provided by W3C, to validate your website code:Validate HTML5Validator.nu is a validator, which validates HTML5, ARIA, SVG 1.1 and MathML 2.0. It checks the complete document and points out where the markup isn’t following the doctype.W3C Markup ValidatorIt checks the HTML doctype and the markup. This validator is for those who are using HTML4 or XHTML1.x doctype. It also validates HTML5, but Validator.nu is considered far better since ... Read More

How exactly does

How to print a triangle formed of '#' using JavaScript?

Shubham Vora
Updated on 15-Sep-2022 12:39:41

4K+ Views

In this tutorial, we will learn to print a triangle formed of '#' using JavaScript. You need to use nested loops to print a triangle formed of '#' in JavaScript. Loop is one of the features in programming languages that executes a set of instructions a several till the condition does not evaluate as false. Nested loops are the loops that contain a loop inside a loop itself. We are going to use two of loops in JavaScript to execute our task. Following are the loops we are using to print a triangle formed of '#' − for loop ... Read More

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

477 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

Advertisements