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
Joining two hash tables in Javascript
Sometimes we need to combine hash tables together using a join function to create a new merged hash table. We'll write a static join method that takes 2 HashTables and creates a new HashTable with all the values. For simplicity, values from the second hash table will override values from the first one if there are duplicate keys. Syntax static join(table1, table2) { // Implementation logic return newHashTable; } Implementation Here's the complete implementation of the join method: class HashTable { ...
Read MoreHow to create an off-canvas menu with CSS and JavaScript?
An off-canvas menu is a sidebar navigation that slides in from the side of the screen when activated. This design pattern is popular in responsive web design as it saves screen space while providing easy access to navigation links. Off-canvas menus are particularly useful for mobile devices and websites with numerous navigation items that don't fit in a traditional horizontal navigation bar. They can slide from left-to-right or right-to-left, and often overlay or push the main content aside. HTML Structure First, create the HTML structure with a sidebar navigation and main content area: ...
Read MoreExplain focus events in JavaScript
Focus events in JavaScript are triggered when HTML elements gain or lose focus on a web page. These events are essential for creating interactive user interfaces and handling form interactions effectively. Focus events occur when users interact with focusable elements like input fields, buttons, or links through clicking, tabbing, or keyboard navigation. Understanding these events helps create responsive and accessible web applications. Types of Focus Events JavaScript provides four main focus events: focus − Triggered when an element gains focus. Does not bubble up the DOM tree. blur − ...
Read MoreHow to merge objects into a single object array with JavaScript?
In JavaScript, you can merge multiple objects from an array into a single object using various methods. This is useful when you have an array of objects with different properties and want to combine them. Using Object.assign() The Object.assign() method copies properties from source objects to a target object. Using the spread operator with it merges all objects in an array: Merge Objects body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { ...
Read MoreLooping in JavaScript to count non-null and non-empty values
In JavaScript, counting non-null and non-empty values in an array is a common task. This article demonstrates how to use forEach() to iterate through an array and count valid values. Basic Array Example Let's start with an array containing subject names: let subjectNames = ['JavaScript', 'Angular', 'AngularJS', 'Java']; console.log("Original array:", subjectNames); Original array: [ 'JavaScript', 'Angular', 'AngularJS', 'Java' ] Using forEach() to Count Valid Values The forEach() method executes a function for each array element. Here's the syntax: yourArrayName.forEach(element => { // Your logic ...
Read MoreCheck if value of an object of certain class has been altered in JavaScript and update another value based on it?
In JavaScript, you can monitor changes to object properties and automatically update dependent values using getters and setters. This approach allows you to create reactive properties that respond when other properties change. Basic Property Monitoring with Getters The simplest approach uses getter methods to access current property values: class Student { constructor(studentMarks1, studentMarks2) { this.studentMarks1 = studentMarks1; this.studentMarks2 = studentMarks2; var self = this; ...
Read MoreDoes this array contain any majority element - JavaScript
Given an array of numbers, any element of the array will be a majority element if that element appears more than array length's 1/2 times in the array. For example, if the length of array is 7, then if there's any element in the array that appears for at least 4 number of times, it will be considered a majority. It's quite apparent that any particular array can have at most one majority element. We are required to write a JavaScript function that takes in an array of numbers with repetitive values and returns true if there exists ...
Read MoreWhat are JavaScript Identifiers?
JavaScript identifiers are names given to variables, functions, classes, objects, and other entities in your code. They work similarly to identifiers in other programming languages like C, C++, and Java, but have specific rules you must follow. What are Identifiers? An identifier is simply a name that you create to reference a variable, function, or other code element. Here are some examples of valid identifiers: // Valid variable identifiers let userName = "John"; let age = 25; let _privateVar = "hidden"; let $element = "jQuery style"; let camelCaseVariable = "standard naming"; console.log(userName); console.log(age); console.log(_privateVar); ...
Read MoreHow to set the opacity level for an element with JavaScript?
Use the opacity property in JavaScript to set the opacity level for any element. The opacity value ranges from 0 (completely transparent) to 1 (completely opaque). Syntax element.style.opacity = "value"; Where value is a number between 0 and 1: 0 - Completely transparent (invisible) 0.5 - 50% transparent 1 - Completely opaque (default) Example: Basic Opacity Control #box { width: 450px; ...
Read MoreHTML5 SVG css3 transition on fill not working when there is external link
CSS3 transitions on SVG fill properties don't work when links are in a visited state due to browser security restrictions. Browsers limit styling capabilities for visited links to prevent privacy attacks. The Problem When an SVG element is inside a visited link, CSS transitions on the fill property are disabled by the browser. This is a security feature to prevent websites from detecting your browsing history. Solution: Adding Random Query Parameters The most effective solution is to add a random query parameter to your URLs, making each link appear "unvisited" to the browser.
Read More