Articles on Trending Technologies

Technical articles with clear explanations and examples

How to display only the current year in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 538 Views

To display only the current year in JavaScript, use the getFullYear() method with the Date object. This method returns a four-digit year as a number. Syntax new Date().getFullYear() Example: Display Current Year in HTML Current Year Display The Current Year: document.getElementById("currentYear").innerHTML = new Date().getFullYear(); ...

Read More

Corner digit number difference - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 175 Views

We are required to write a JavaScript function that takes in a number, constructs a new number from the first and last digit of that number and returns the difference between the original number and the number thus formed. For example: If the input is 34567 Then the corner digits number will be: 37 And the output will be: 34530 Algorithm The solution involves extracting the first and last digits, combining them to form a corner number, then calculating the difference. Example Following is the code: ...

Read More

Returning the highest number from object properties value – JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 843 Views

When working with JavaScript objects, you might need to find the property with the highest value. For example, finding the highest rating from a property rating system. Suppose we have an object that contains ratings of a property over some criteria like this: const rating = { "overall": 92, "atmosphere": 93, "cleanliness": 94, "facilities": 89, "staff": 94, "security": 92, "location": 88, "valueForMoney": 92 } We need to write a JavaScript function ...

Read More

How to access properties of an array of objects in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 5K+ Views

In JavaScript, accessing properties of objects within an array is a common task. Whether you're working with a single object or an array of objects, there are several methods to retrieve property values effectively. JavaScript objects are collections of key-value pairs called properties. When you have an array containing multiple objects, you need specific techniques to access the properties of each object. Let's explore the main approaches. Using Dot Notation Dot notation is the most straightforward way to access object properties when the property name is known and is a valid JavaScript identifier. The syntax is object.propertyName. ...

Read More

How to allow long and unbreakable words to be broken and wrap to the next line in JavaScript?

V Jyothi
V Jyothi
Updated on 15-Mar-2026 453 Views

Use the wordWrap CSS property in JavaScript to allow long and unbreakable words to be broken and wrap to the next line. This property is especially useful when dealing with long URLs, email addresses, or continuous text that would otherwise overflow their container. Syntax element.style.wordWrap = "break-word"; wordWrap Property Values Value Description normal Default behavior - only ...

Read More

Setting null values with an HTML using AngularJS.

Arjun Thakur
Arjun Thakur
Updated on 15-Mar-2026 202 Views

In AngularJS, setting null values in select dropdowns requires proper model initialization and template configuration. This approach is useful when you want to handle undefined or empty selections. Controller Setup First, define the controller with a null-initialized model and populate the options array: function display($scope) { $scope.obj = {"selected": null}; $scope.objects = [{id: 1, value: "Yes"}, {id: 0, value: "No"}]; } HTML Template The template uses ng-options to populate the dropdown and includes a default "Unknown" option: ...

Read More

Test if the HTML attribute tabindex is present and get the value

Nitya Raut
Nitya Raut
Updated on 15-Mar-2026 546 Views

To test if the HTML attribute tabindex is present and get its value, you can use jQuery's attr() method or JavaScript's hasAttribute() method. Using jQuery attr() Method The attr() method returns the attribute value if it exists, or undefined if the attribute is not present: Element with tabindex Element without tabindex // Get tabindex value ...

Read More

Write the main difference between '==' and '===' operators in javascript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 253 Views

The main difference between == and === operators in JavaScript is that == performs type coercion (converts types before comparing), while === performs strict comparison without any type conversion. The == Operator (Loose Equality) The == operator compares values after converting them to the same type if needed. This can lead to unexpected results. Example var x = 5; var y = "5"; var z = 6; document.getElementById("loose").innerHTML = (x == y) + "" + (x == z); Output true false Notice ...

Read More

How to compare two objects in JavaScript?

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 24K+ Views

Objects in JavaScript are entities that consist of properties and types. For example, a car object might have properties like color, price, height, and width. const car = { color: 'Black', price: 2500000, height: '6 feet', width: '5 feet' } The equality operator (===) verifies whether two operands are equal and returns a Boolean value. However, it cannot directly compare objects because objects are reference types. document.write('tutorix' === 'tutorix' ...

Read More

First and last child node of a specific node in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 925 Views

In JavaScript, you can access the first and last child nodes of any DOM element using built-in properties. There are four key properties: firstChild, lastChild, firstElementChild, and lastElementChild. Key Differences The main difference between these properties is how they handle whitespace and text nodes: firstChild and lastChild return any node, including text nodes (whitespace) and comments firstElementChild and lastElementChild return only HTML element nodes, ignoring whitespace and comments Syntax // First child properties element.firstChild // Returns any node (including text/whitespace) element.firstElementChild // Returns only element ...

Read More
Showing 16951–16960 of 61,297 articles
Advertisements