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
Front End Technology Articles
Page 282 of 652
How to implement enqueue and dequeue using only two stacks in JavaScript?
In this tutorial, we'll implement a queue using only two stacks. This is a common data structure interview question that demonstrates understanding of both queues (FIFO - First In, First Out) and stacks (LIFO - Last In, First Out). Algorithm STEP 1 − We have two stacks: one for enqueuing (input) and one for dequeuing (output). STEP 2 − We enqueue by pushing onto the enqueue stack. STEP 3 − We dequeue by popping from the dequeue stack. STEP 4 − ...
Read MoreHow to create infix to postfix converter in JavaScript?
An infix to Postfix converter is a tool that converts an infix expression to a postfix expression. In this tutorial, we will build the infix to postfix converter using JavaScript. What is an infix expression? Infix expression is an expression in which the operators are between the operands. For example, the expression "3 + 4" is an infix expression. What is a postfix expression? A postfix expression is an expression in which the operators are after the operands. For example, the expression "3 4 +" is a postfix expression. How does the Infix to Postfix converter work? ...
Read MoreWhat is Variable Shadowing in JavaScript?
In programming, shadowing occurs when a variable declared in a certain scope (e.g. a local variable) has the same name as a variable in an outer scope (e.g. a global variable). When this happens, the outer variable is said to be shadowed by the inner variable. In JavaScript, variables can be shadowed in both the global and function scope. Global variables can be shadowed by function-scoped variables, and function-scoped variables can be shadowed by block-scoped variables declared with the let or const keyword. Variable Shadowing in the Global Scope In the global scope, shadowing occurs when a ...
Read MoreHow to Generate Random Birthday Wishes using JavaScript?
In this tutorial, we will learn how to generate a random birthday wish using JavaScript. We will use the Math.random() method to generate a random number and select a birthday wish from an array of wishes. The Math.random() Method The Math.random() method is a built-in function in JavaScript that returns a random number between 0 (inclusive) and 1 (exclusive). console.log(Math.random()); // 0.6789234567 console.log(Math.random()); // 0.1234567890 0.6789234567 0.1234567890 Creating the Array of Birthday Wishes First, we'll create an array containing various birthday wishes: var wishes = [ ...
Read MoreHow to return an object by parsing http cookie header in JavaScript?
Cookies are small pieces of data that are sent from a website to a user's web browser. They are used to store information about the user, such as their preferences or login status. When a user visits a website, their web browser will send a request to the server. The server will then send a response, which includes a set of headers. One of these headers is the "Cookie" header, which contains a list of all the cookies that are associated with the website. Understanding Cookie Headers Cookie headers can contain multiple name-value pairs separated by semicolons. ...
Read MoreHow to make active tab in navigation menu using HTML CSS & JavaScript?
Creating an active tab navigation menu helps users understand which page or section they're currently viewing. This tutorial demonstrates how to build an interactive navigation menu using HTML, CSS, and JavaScript with proper active state management. HTML Structure The HTML structure uses a simple unordered list with navigation items. Each li element represents a tab, and anchor tags provide the clickable links. Home About Services Portfolio Contact CSS Styling The CSS creates the visual design and ...
Read MoreHow to filter values from an array using the comparator function in JavaScript?
In JavaScript, filtering an array can be done by using the filter() method. This method creates a new array with all elements that pass the test implemented by the provided callback function (comparator function). Syntax arr.filter(callback) Here callback is a comparator function used to test each element in the array arr. It should return true to keep the element, or false to filter it out. Using Array.filter() Method The most efficient way to filter values is using the built-in filter() method. Here's an example filtering odd numbers: ...
Read MoreHow to get index in a sorted array based on iterator function in JavaScript?
When working with sorted arrays in JavaScript, you often need to find the correct insertion position for a new element to maintain the sorted order. This article explores different methods to achieve this using iterator functions. Using Binary Search for Insertion Index The most efficient approach is to implement a binary search algorithm that finds the insertion point without modifying the original array. function findInsertionIndex(arr, value, compareFunction) { let left = 0; let right = arr.length; while (left < ...
Read MoreHow to render a list without rendering an engine in JavaScript?
In this tutorial, we'll explore how to render a list dynamically in JavaScript without using a rendering engine like React or Vue. We'll demonstrate various methods to create lists directly in the DOM using vanilla JavaScript and jQuery. Using Array.forEach() Method The Array.forEach() method iterates over an array and executes a callback function for each element. This is ideal for creating list items dynamically. forEach Example Rendering the list using the Array.forEach() Method ...
Read MoreHow to create a function that invokes each provided function using JavaScript?
In JavaScript, functions are first-class objects, which means they can be passed as arguments to other functions. This powerful feature enables creating functions that can invoke multiple other functions systematically. The "invoke-each" pattern creates a function that invokes each provided function with the same set of arguments. This pattern is particularly useful for executing multiple operations with shared data. Why Use the Invoke-Each Pattern? The invoke-each pattern serves several important purposes: Abstraction: It hides the complexity of invoking multiple functions, making code cleaner and more maintainable. Batch Operations: Execute ...
Read More