Found 9053 Articles for Front End Technology

How to define a function in JavaScript?

Srinivas Gorla
Updated on 15-Jun-2020 12:04:16

142 Views

The most common way to define a function in JavaScript is by using the “function” keyword, followed by a unique function name, a list of parameters (that might be empty), and a statement block surrounded by curly braces.SyntaxHere’s the syntax −     Try the following example. It defines a function called sayHello that takes no parameters,    

What is a default constructor in JavaScript?

mkotla
Updated on 12-Jun-2020 14:04:17

651 Views

If a constructor method is not added, then a default constructor should be used. A default constructor is created when nothing is defined.SyntaxHere’s the syntax −constructor() {}The syntax for derived class −constructor(...args) {    super(...args); }

How to show if...else statement using a flowchart in JavaScript?

Sai Subramanyam
Updated on 30-Jul-2019 22:30:22

147 Views

The if statement is the fundamental control statement that allows JavaScript to make decisions and execute statements conditionally. Let’s see how to show if…else statement using flowchart in JavaScript.

What is the best way to compare two strings in JavaScript?

Fendadis John
Updated on 08-Jan-2020 09:40:36

11K+ Views

To compare two strings in JavaScript, use the localeCompare() method. The method returns 0 if both the strings are equal, -1 if string 1 is sorted before string 2 and 1 if string 2 is sorted before string 1.ExampleYou can try to run the following code to compare two stringsLive Demo           Compare Strings                      function compareStr() {             var string1 = "World";             var string2 = "World";             var result = string1.localeCompare(string2);             document.getElementById("test").innerHTML = result;          }          

How do you reverse a string in place in JavaScript?

Shubham Vora
Updated on 26-Jul-2022 07:37:53

2K+ Views

In this tutorial, we will learn to reverse a string in place in JavaScript. How to reverse a string is one of the most popular questions asked in the interview of freshers. It’s an easy task but the interviewer can be tricky and make the same question difficult for you. For example, what if the interviewer asks you to write a pseudo code to reverse a string in place without using the extra space? You should have an answer ready in your mind for this kind of tricky question.There are lots of ways to reverse a string. As developers develop ... Read More

How to show a while loop using a flow chart in JavaScript?

Sai Subramanyam
Updated on 30-Jul-2019 22:30:21

175 Views

The purpose of a while loop is to execute a statement or code block repeatedly as long as an expression is true. Once the expression becomes false, the loop terminates. Let’s see how to show while loop using flowchart in JavaScript −

How to show for loop using a flowchart in JavaScript?

Lakshmi Srinivas
Updated on 12-Jun-2020 13:58:53

673 Views

The “for” loop includes loop initialization where we initialize our counter to a starting value. The initialization statement is executed before the loop begins, the test statement which will test if a given condition is true or not. If the condition is true, then the code given inside the loop will be executed, otherwise, the control will come out of the loop.At the end comes the iteration statement where you can increase or decrease your counter. Let us see how to show for loop using flowchart in JavaScript −

What is an alert box in JavaScript?

Krantik Chavan
Updated on 12-Jun-2020 13:58:13

1K+ Views

An alert dialog box is mostly used to give a warning message to the users. For example, if one input field requires to enter some text but the user does not provide any input, then as a part of validation, you can use an alert box to give a warning message.Nonetheless, an alert box can still be used for friendlier messages. Alert box gives only one button "OK" to select and proceed.ExampleYou can try to run the following code to learn how to add an alert box −Live Demo                                         Click the following button to see the result:                          

How to validate a date pattern in JavaScript?

Shubham Vora
Updated on 31-Oct-2022 11:49:44

370 Views

In this tutorial, we will learn how to validate a date pattern in JavaScript. The Date object in JavaScript represents a single point in time in a platform-independent way. It carries a number representing time in milliseconds since January 1, 1970, at 00:00:00. (UTC). The Date object can format differently, so it is essential to validate a date pattern before using it. In this tutorial, we will discuss two ways to validate a date pattern in JavaScript − Using the getTime() method Using the Date constructor and split() method Validate a Date Pattern using the getTime() Method In ... Read More

How to use window.location to redirect to a different URL with JavaScript?

Nishtha Thakur
Updated on 12-Jun-2020 13:43:23

359 Views

You might have encountered a situation where you clicked a URL to reach a page X but internally you were directed to another page Y. It happens due to page redirection.It is quite simple to do a page redirect using JavaScript on the client side. To redirect your site visitors to a new page, you just need to add a line in your head section as follows −ExampleYou can try to run the following code to learn how to use window.location to redirect to another URL. Here, we will redirect to the home pageLive Demo           ... Read More

Advertisements