What is the difference between "strict" and "non-strict" modes of JavaScript?

Abhinanda Shri
Updated on 15-Mar-2026 23:18:59

1K+ Views

The "use strict" is a directive introduced in JavaScript 1.8.5 that enables strict mode execution. In strict mode, JavaScript enforces stricter parsing and error handling, while non-strict mode (the default) is more permissive and allows certain problematic practices. Enabling Strict Mode To enable strict mode, add "use strict"; at the beginning of your script or function. For global scope, place it at the top of the script file. Check the console for errors (F12) ... Read More

With JavaScript RegExp search a carriage return character.

Ayyan
Updated on 15-Mar-2026 23:18:59

779 Views

To find carriage return characters with JavaScript Regular Expression, use the \r metacharacter. This pattern matches the carriage return character (ASCII code 13) in strings. Syntax /\r/ Example: Finding Carriage Return Position The following example shows how to search for a carriage return character and return its position in the string: JavaScript Regular Expression ... Read More

How to set the right position of a positioned element with JavaScript?

Shubham Vora
Updated on 15-Mar-2026 23:18:59

3K+ Views

In this tutorial, we shall learn to set the right position of a positioned element with JavaScript. What is a positioned element? The available position values in CSS are relative, absolute, fixed, or static. The static position is the default position value. Static elements are in the document order. A positioned element's position is based on its properties like the top, right, bottom, and left. We must set the position in every direction to align the elements as required. Here we are going to see the right position property. Using the right Property With this ... Read More

What are the advantages of CSS?

Ankitha Reddy
Updated on 15-Mar-2026 23:18:59

17K+ Views

CSS or Cascading Style Sheets is used to design web pages, helping web developers control the layout and other visual aspects of websites. Using CSS, you can control the color of text, the style of fonts, spacing between paragraphs, how columns are sized and laid out, and what background images or colors are used. In this article, we will discuss the various advantages of CSS and why it's essential for modern web development. Key Advantages of CSS 1. Consistent Design Across Multiple Pages CSS enables uniform design across an entire website. By creating an external stylesheet and linking ... Read More

How to access a function property as a method in JavaScript?

vineeth.mariserla
Updated on 15-Mar-2026 23:18:59

1K+ Views

In JavaScript, object properties can hold functions, which become methods when accessed through the object. A method is simply a function that belongs to an object and can access the object's other properties using the this keyword. Syntax const object = { property1: value1, property2: value2, methodName: function() { return this.property1 + this.property2; } }; // Call the method object.methodName(); Example 1: Employee Object with fullName Method Here's an ... Read More

Sort array by year and month JavaScript

AmitDiwan
Updated on 15-Mar-2026 23:18:59

3K+ Views

Sorting arrays of objects by multiple criteria is a common requirement in JavaScript applications. In this tutorial, we'll learn how to sort an array by year first, then by month for objects with the same year. The Problem We have an array of objects containing year and month properties: const arr = [{ year: 2020, month: 'January' }, { year: 2017, month: 'March' }, { year: 2010, month: 'January' }, { ... Read More

Return the difference between the maximum & minimum number formed out of the number n in JavaScript

AmitDiwan
Updated on 15-Mar-2026 23:18:59

442 Views

We have to write a function that takes a positive number n and returns the difference between the maximum number and the minimum number that can be formed from its digits. For example, if the number n is 203: The maximum number that can be formed from its digits will be 320 The minimum number that can be formed from its digits will be 23 (placing the zero at one's place) And the difference will be: 320 - 23 = 297 Therefore, the output should ... Read More

Attach event to dynamic elements in JavaScript?

AmitDiwan
Updated on 15-Mar-2026 23:18:59

261 Views

To attach events to dynamic elements in JavaScript, use event delegation with document.addEventListener(). This technique listens on a parent element (like document) and handles events from child elements that may be created dynamically. Why Event Delegation? When elements are added to the DOM dynamically (after the page loads), direct event listeners won't work because they weren't attached when the element was created. Event delegation solves this by using event bubbling. Basic Event Delegation Example Dynamic Events Example ... Read More

Object to array - JavaScript

AmitDiwan
Updated on 15-Mar-2026 23:18:59

383 Views

Converting an object to an array of key-value pairs is a common task in JavaScript. There are several built-in methods to achieve this transformation. Sample Object Let's start with this example object: const obj = { name: "Vikas", age: 45, occupation: "Frontend Developer", address: "Tilak Nagar, New Delhi", experience: 23, salary: "98000" }; Using Object.entries() (Recommended) The simplest approach is using Object.entries(), which directly converts an object to an ... Read More

Removing redundant elements from array altogether - JavaScript

AmitDiwan
Updated on 15-Mar-2026 23:18:59

393 Views

We are required to write a function that takes in an array and returns a new array that have all duplicate values removed from it. The values that appeared more than once in the original array should not even appear for once in the new array. For example, if the input is: const arr = [763, 55, 43, 22, 32, 43, 763, 43]; The output should be: const output = [55, 22, 32]; Understanding the Approach We will be using the following two methods: ... Read More

Advertisements