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 by vineeth.mariserla
Page 3 of 8
JavaScript's Boolean function?
The Boolean() function in JavaScript converts any value to its boolean equivalent (true or false). This is useful for conditional checks and validation in your applications. Syntax Boolean(value); It takes any value or expression and returns true for truthy values and false for falsy values. Falsy Values These values always return false when converted to boolean: console.log(Boolean(0)); // false console.log(Boolean("")); // false (empty ...
Read MoreHow to return an array whose elements are the enumerable property values of an object in JavaScript?
We can use various methods to get values and keys from an object, but those methods will not return the values as an array, which is very useful in many cases. JavaScript provides the Object.values() method to get an array whose elements are the enumerable property values of an object. Syntax Object.values(obj); This method takes an object as an argument and returns an array whose elements are the property values of the object. Parameters obj: The object whose enumerable property values are to be returned. Return Value An array containing the ...
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 MoreFirst element and last element in a JavaScript array?
An array is a group of elements where each element has its own index value. We can access any element using these indexes. For the first element, the index is always 0, but for the last element, we need to use the array's length property to calculate the correct index. Accessing the First Element Since arrays are zero-indexed in JavaScript, the first element is always at index 0. If the array is arr, then the first element is arr[0]. Example In the following example, we have two arrays and we'll access their first elements using index ...
Read MoreWhat is the importance of _without() method in JavaScript?
The _.without() method is part of the Underscore.js library that creates a new array by excluding specified values from an original array. It performs case-sensitive matching and removes all occurrences of the specified values. Syntax _.without(array, *values) Parameters array - The source array to filter *values - One or more values to exclude from the array Return Value Returns a new array with the specified values removed, preserving the original array order. Example: Removing Numbers The following example removes multiple numeric values from an array: ...
Read MoreHow to get the pixel depth and color depth of a screen in JavaScript?
The JavaScript window object provides methods to get screen display information through the screen object. Two important properties are screen.colorDepth and screen.pixelDepth which return the color depth and pixel depth of the browser screen respectively. Color Depth The screen.colorDepth property returns the number of bits used to display one color on the screen. Modern computers typically use 24-bit or 32-bit hardware for color resolution, where: 24-bit color: Supports 16.7 million colors (True Color) 32-bit color: Includes an alpha channel for transparency Syntax screen.colorDepth Example ...
Read MoreHow to convert a string in to a function in JavaScript?
To convert a string into a function in JavaScript, the eval() method can be used. This method takes a string as a parameter and evaluates it as JavaScript code, which can include function definitions. Syntax eval(string); Example: Converting String to Function In the following example, a string contains a JSON object where the 'age' property holds a function as a string. Using eval(), we convert this string into an actual executable function. var string = '{"name":"Ram", "age":"function() {return 27;}", "city":"New jersey"}'; var fun ...
Read More