- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 6685 Articles for Javascript
2K+ Views
Iterator functions are used to iterate through arrays, lists, and other data structures. In JavaScript, there are several ways to get the index at which a value should be inserted into a sorted array. Using the Array sort() and indexOf() Methods The sort() method can be used to sort an array in ascending or descending order. The default sort order is ascending, so if you want to get the index at which a value should be inserted into a sorted array, you can use the sort() method with a compare function. After the array is sorted we could apply the ... Read More
613 Views
In JavaScript, filtering an array can be done by using the filter() method. This method is used to create a new array with all the elements that pass the condition provided in the callback function. However, what if we want to filter out the values for which the comparator function does not return true? Syntax arr.filter(compare) Here compare is a comparator function used to compare the elements in the array arr. We could define it to return true or false. On the basis of the return value of the compare function, the function “filter” filters the array. Algorithm ... Read More
13K+ Views
With the help of HTML, CSS, and JavaScript, it is possible to create a navigation menu with a curved active tab. This can be done by using the ::before and ::after pseudo-elements to create the desired shape, and then using JavaScript to add the active class to the element. HTML The HTML for this navigation menu is very simple. There is a ul element with a class of "nav" and within that, there are six li elements, each with a class of "nav-item". Home About Services Portfolio ... Read More
3K+ Views
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. Parsing the Cookie Header In order to parse the Cookie header, we need to first split ... Read More
1K+ Views
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 between 1 and 10. This number will be used to 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). Generating a Random Birthday Wish To generate a random birthday wish, we will use the Math.random() method to generate a random number between 1 and 10. This number will be used ... Read More
4K+ Views
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 variable declared with ... Read More
966 Views
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? The converter first ... Read More
1K+ Views
In this tutorial, we'll be implementing a queue using only two stacks. This is a pretty common interview question so it's good to know how to do it. Algorithm STEP 1 − We have two stacks, one for enqueueing and one for dequeueing. STEP 2 − We enqueue by pushing onto the enqueue stack. STEP 3 − We dequeue by popping from the dequeue stack. STEP 4 − If the dequeue stack is empty, we pop everything from the enqueue stack and push it onto the dequeue stack. STEP 5 − This reverses the order so that ... Read More
1K+ Views
In JavaScript, a predicate function is a function that returns a Boolean value. In other words, it is a function that tests whether a certain condition is true or false.There are times when we need to negate a predicate function. That is, we need to return the opposite Boolean value.There are several ways to negate a predicate function in JavaScript.Using the ! operatorThe most common way to negate a predicate function is to use the ! operator.For example, consider the following predicate function −function isEven(num) { return num % 2 === 0; }To negate this function, we can use ... Read More
2K+ Views
JavaScript has a built-in function called replace() that can be used to replace characters in a string. This function takes two arguments: the first argument is the character or characters to be replaced, and the second argument is the character or characters to replace them with. Syntax Following is the syntax to replace characters except last with a specified mask − str.replace(/.(?=.)/g, "x"); The first argument to the replace() method is character/s to be replaced. We pass a regular expression for all characters except last as the first argument to the replace method. All characters except the last are ... Read More