Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles on Trending Technologies
Technical articles with clear explanations and examples
How to label a block in JavaScript?
A block statement groups zero or more statements. In languages other than JavaScript, it is known as a compound statement. Labels in JavaScript provide a way to identify blocks of code, which is particularly useful for controlling nested loops with break and continue statements. Syntax Here's the basic syntax for a block statement: { // List of statements } To add a label to a block, use the following syntax: labelName: { // Statement list } Labeling Loops Labels are most commonly used ...
Read MoreWhat is onclick event in JavaScript?
The onclick event is one of the most frequently used JavaScript events. It triggers when a user clicks an HTML element, typically with the left mouse button. Syntax The onclick event can be added in three ways: // Method 1: Inline HTML attribute Click Me // Method 2: Element property element.onclick = function() { /* code */ }; // Method 3: Event listener (recommended) element.addEventListener('click', function() { /* code */ }); Example: Inline onclick The simplest approach is using the onclick attribute directly in HTML: ...
Read MoreWhat is a block statement in JavaScript?
A block statement groups zero or more statements within curly braces {}. In languages other than JavaScript, it is known as a compound statement. Block statements are commonly used with control structures like if, for, and while. Syntax Here's the basic syntax: { // List of statements statement1; statement2; // ...more statements } Block Scoping with var vs let/const Variables declared with var do not have block scope - they are function-scoped or globally-scoped. However, let and const are block-scoped. ...
Read MoreWhat is the difference between break with a label and without a label in JavaScript?
In JavaScript, the break statement is used to exit loops. Without a label, it exits only the innermost loop. With a label, it can exit any labeled loop, even outer ones in nested structures. Break Without Label The break statement without a label exits only the current loop it's inside. It cannot jump out of nested loops to an outer level. Example var x = 1; document.write("Entering the loop "); ...
Read MoreWhat is a default constructor in JavaScript?
In JavaScript classes, if you don't define a constructor method, the JavaScript engine automatically provides a default constructor. This default constructor is implicit and handles basic object initialization. What is a Default Constructor? A default constructor is an empty constructor that JavaScript creates automatically when no explicit constructor is defined in a class. It performs minimal initialization and, for derived classes, calls the parent constructor. Syntax For base classes, the default constructor is equivalent to: constructor() {} For derived classes (classes that extend another class), the default constructor is: constructor(...args) ...
Read MoreHow to show if...else statement using a flowchart in JavaScript?
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. If...Else Statement Flowchart Start Condition? True False ...
Read MoreHow do you reverse a string in place in JavaScript?
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 ...
Read MoreHow to show a while loop using a flow chart in JavaScript?
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. While Loop Flowchart The flowchart below illustrates the execution flow of a while loop: START ...
Read MoreHow to show for loop using a flowchart in JavaScript?
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: For Loop Flowchart ...
Read MoreWhat is an alert box in JavaScript?
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. Syntax alert(message); Parameters: message - The text to display in the alert dialog box Example ...
Read More