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
Programming Articles
Page 2 of 2547
Write the main difference between '==' and '===' operators in javascript?
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 Morewhat is the main difference between '=' and '==' operators in javascript?
In JavaScript, the = operator is used for assignment, while the == operator is used for equality comparison. Understanding this difference is fundamental to writing correct JavaScript code. The Assignment Operator (=) The = operator assigns a value from the right side to the variable on the left side. It does not compare values. var x = 5; // Assigns 5 to variable x var y = "6"; // Assigns string "6" to variable y var z = x; ...
Read MoreExplain about logical not(!) operator in detail with example in javascript?
The logical NOT operator (!) is a unary operator that inverts boolean values. It returns true for falsy values and false for truthy values. Syntax !expression How It Works The NOT operator first converts the operand to a boolean value, then returns its opposite: If the operand is truthy, it returns false If the operand is falsy, it returns true Example with Boolean Values document.getElementById("boolean-demo").innerHTML = "!true = " + !true ...
Read MoreWrite a number array and add only odd numbers?
In JavaScript, you can sum only the odd numbers from an array by using the modulus operator (%) to check if a number is odd, then adding it to a running total. How It Works The modulus operator returns the remainder when a number is divided by 2. If the remainder is not equal to 0, the number is odd. Example: Summing Odd Numbers var tot = 0; var a = [1, 45, 78, 9, 78, 40, 67, 76]; ...
Read MoreHow to add an element to a JavaScript object?
In JavaScript, objects are real-time entities that contain properties and methods. Objects store data in key-value pairs, where keys are called properties and values are called property values. There are multiple ways to add new properties to existing JavaScript objects. Let's explore the most common approaches. Object Creation Syntax var obj = new Object(); Or using object literal syntax: var obj = {property1: value1, property2: value2}; Using Dot (.) Operator The dot operator is the most common way to add properties to JavaScript objects. It acts as a connector ...
Read MoreHow to stop form submission using JavaScript?
In this tutorial, we will see the methods to stop form submission using JavaScript. Generally, the HTML form by default submits automatically when certain events are triggered. The automatic submission causes the browser to refresh and reload the whole page, which we don't want in some cases. To perform any operation before submission, we need to change the default behavior of the form to prevent it from submitting. Following are the methods we can use to stop form submission: Using the "return false" value Using the preventDefault() method Let ...
Read MoreHow to display output in javascript?
JavaScript provides several methods to display output to users. Here are the four most common approaches for displaying data in web applications. Using innerHTML to Display in HTML Elements The innerHTML property allows you to insert content directly into HTML elements on your webpage. document.getElementById("demo").innerHTML = "Hello, World!"; Hello, World! Using document.write() Method The document.write() method writes content directly to the HTML document. ...
Read MoreWrite the syntax of javascript with a code to demonstrate it?
JavaScript Tags JavaScript code must be placed within HTML tags to execute properly. These script tags can be positioned in different locations within an HTML document. Where to Place JavaScript JavaScript can be embedded in three main locations: Head section: Scripts in the tag load before the page content Body section: Scripts in the tag execute as the page loads External file: Scripts can be linked from separate .js files Basic JavaScript Syntax JavaScript syntax includes variables, functions, and DOM ...
Read MoreWhat are the types of tags involved in javascript?
In JavaScript, there are several types of HTML tags that work with JavaScript code. The most important is the tag, which is essential for embedding or linking JavaScript in web pages. HTML Tag The tag is used to define client-side scripts in HTML documents. It can contain JavaScript code directly or reference an external JavaScript file. All JavaScript code must be placed within tags to be executed by the browser. Types of Script Tags Inline JavaScript JavaScript code written directly inside the tag: ...
Read MoreWhat is the difference between Math.ceil() and Math.round() methods in JavaScript?
Math.ceil() and Math.round() are JavaScript methods that round numbers to integers, but they work differently. Math.ceil() always rounds up to the nearest integer, while Math.round() rounds to the nearest integer using standard rounding rules (0.5 and above rounds up, below 0.5 rounds down). Math.ceil() - Always Rounds Up The Math.ceil() method rounds a number up to the nearest integer, regardless of the decimal value. It always moves toward the greater value. Syntax Math.ceil(x) Example ...
Read More