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 detect that JavaScript Cookies are disabled?
This tutorial will teach you how to detect if cookies are enabled or disabled on a website using JavaScript. Cookies are small text files stored on your computer that contain data. When a web server sends a web page to a browser, it terminates the connection and forgets about the user. Cookies solve the challenge of "how to remember information about the user" by storing data like usernames for subsequent visits. Cookies allow you to store user information between page visits. Your server transmits certain data to the visitor's browser in the form of a cookie, which may be ...
Read MoreHow to get the innerHTML of a cell with JavaScript DOM?
In this tutorial, we will learn how to get the innerHTML of a cell with JavaScript DOM. The innerHTML property allows us to access the HTML content inside table cells by first accessing the table structure through the DOM. We can manipulate the DOM (Document Object Model) easily using document.getElementById(). This method returns the element object that represents the element whose id is specified in the parameter. Since every element's id is unique, we can easily access specific table elements and then use the innerHTML property to retrieve the content of table cells. Using Table Cells Collection ...
Read MoreHow to get the Width and Height of the screen in JavaScript?
In this article, we are going to discuss how to get the width and height of the screen in JavaScript. JavaScript provides a window.screen object that contains information regarding the user's screen. The information includes height and width, and also many other features like color depth and pixel density. To find the height and width of the screen you need to use the following read-only properties: screen.height − This property returns the height of the screen in pixels. screen.width − This property returns the width of the screen in pixels. ...
Read MoreBinary Search program in JavaScript
The binary search algorithm works on the divide and conquer principle as it keeps dividing the array in half before searching. To search for an element in an array using binary search, the array should be sorted. In the sorted array, we find the middle element and compare it with the element that has to be searched, and based on the comparison, we either search in the left sub-array, right sub-array, or return the middle element. In this article, we are given a sorted array of integers, and our task is to search for the given target element ...
Read MoreHow to define methods for an Object in JavaScript?
Methods are functions that let an object perform actions or have actions performed on it. The key difference between a function and a method is that a function is a standalone unit of statements, while a method is attached to an object and can be referenced using the this keyword. Methods are used for everything from displaying object contents to performing complex mathematical operations on properties and parameters. Method 1: Defining Methods During Object Creation You can define methods directly when creating an object using object literal notation: let person = { ...
Read MoreHow can I simplify the usage of Regular Expressions with JavaScript?
In this tutorial, we will learn to simplify the use of regular expressions in JavaScript. Regular expressions, also called Regex or RegExp, are sequences of characters that define search patterns. They can be simple or complex and work across many programming languages. Let's understand the need for regular expressions with a practical example. Why Should We Use Regular Expressions? Suppose you're developing an application that collects user emails. Users can enter anything in the input field, potentially creating spam records in your database. You need to validate emails before form submission. To validate an email, you ...
Read MoreWhich algorithm does the JavaScript Array#sort() function use?
JavaScript's Array.sort() method doesn't mandate a specific sorting algorithm in the ECMAScript specification. This gives JavaScript engines freedom to choose the most efficient implementation for their environment. Engine-Specific Implementations Different JavaScript engines use different sorting strategies based on performance optimizations and array characteristics. Mozilla Firefox (SpiderMonkey) SpiderMonkey primarily uses merge sort, which provides stable O(n log n) performance. The implementation can be found in Mozilla's C codebase. Chromium/WebKit (V8 Engine) V8 uses a hybrid approach called Timsort (based on merge sort and insertion sort) for optimal performance across different data patterns. The algorithm selection depends on: ...
Read MoreJavaScript tracking the differences between elements in an array
Tracking differences between elements in an array is a fundamental task in data analysis and software development. Whether you're analyzing trends in numerical data, measuring changes over time, or debugging an application's behavior, calculating these differences can provide valuable insights. In JavaScript, this task is often approached using various techniques, including loops and modern functional programming methods like the map() function. Here are two methods to calculate differences between elements in an array: Iterative Loop and Functional Programming using the map. Problem Statement We are given an array of Number literals, and we are required to write ...
Read MoreReduce an array to the sum of every nth element - JavaScript
We are required to write a JavaScript function that takes in an array of numbers and returns the cumulative sum of every number present at the index that is a multiple of n from the array. Let's write the code for this function − Example const arr = [1, 4, 5, 3, 5, 6, 12, 5, 65, 3, 2, 65, 9]; const num = 2; const nthSum = (arr, num) => { let sum = 0; for(let i = 0; i < arr.length; i++){ ...
Read MoreHow to create a table caption with JavaScript DOM?
To create a table caption using JavaScript DOM, use the createCaption() method on a table element. This method adds a element to the table, which displays as a title above the table content. Syntax table.createCaption() Return Value Returns the newly created element, which can be styled or modified with text content. Example Here's how to create a table caption dynamically using JavaScript: function captionFunc(x) { ...
Read More