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
Front End Technology Articles
Page 585 of 652
How to append an item into a JavaScript array?
To append an item to a JavaScript array, use the push() method.ExampleYou can try to run the following code to append an item:Live Demo var arr = ["marketing", "technical", "finance", "sales"]; arr.push("HR"); document.write(arr); Outputmarketing,technical,finance,sales,HR
Read MoreHow to define integer constants in JavaScript?
ECMAScript allows usage of const to define constants in JavaScript. To define integer constants in JavaScript, use the const,const MY_VAL = 5; // This will throw an error MY_VAL = 10;As shown above, MY_VAL is a constant and value 5 is assigned. On assigning, another value to a constant variable shows an error.Using const will not allow you to reassign any value to MY_VAL again. If you will assign a new value to a constant, then it would lead to an error.
Read MoreHow to generate Prime Numbers in JavaScript?
To generate prime numbers in JavaScript, you can try to run the following codeExampleLive Demo JavaScript Prime for (var limit = 1; limit
Read MoreWhat is the difference between parseInt(string) and Number(string) in JavaScript?
parseInt(string)The parseInt() method parses up to the first non-digit and returns the parsed value. For example, the following returns 765:parseInt("765world")Let’s take another example. The following returns 50:parseInt(‘50px”);Number(string)Number() converts the string into a number, which can also be a float BTW.For example, the following returns NaN:Number(“765world”)The following returns NaN:Number(“50px”);
Read MoreDifference between != and !== operator in JavaScript Program
'!=' comparison operator'!=' operator checks the unequality of two objects without making the type check. It converts the datatype of two operands to one and then compares their value. For example 1 != '1' will results false.'!==' comparison operator'!==' operator checks the unequality of two objects with a type check. It does not converts the datatype and makes a typed check.For example 1 !== '1' will results true.Following example, shows usage of '!=' vs '!==' operators.Example Operator Example console.log(" 1 != '1' " + (1 != '1')); ...
Read MoreDifference between "." and "#" selector in CSS
'.' selector'.' selector is a class level selector. The dot operator is used to create a style class which can then be applied on multiple html elements.'#' selector'#' selector is an element level selector. Hash operator is used to applying style on a particular element whose id is the same as used in '#' selectorExampleFollowing the example, shows usage of '.' as well as '#' selector on three div elements. Selector Example>/title> .blackBorder { border: 2px solid black; } #redDiv { ...
Read MoreHow exactly does <script defer=“defer”> work?\\n
The defer attribute is used to specify that the script execution occurs when the page loads. It is used only for external scripts and is a boolean attribute.ExampleThe following code shows how to use the defer attribute:Live Demo The external file added will load later, since we're using defer
Read MoreHow to create JavaScript alert with 3 buttons (Yes, No and Cancel)?
The standard JavaScript alert box won’t work if you want to customize it. For that, we have a custom alert box, which we’re creating using jQuery and styled with CSS.ExampleYou can try to run the following code to create an alert box with 3 buttons i.e Yes, No and Cancel. function functionConfirm(msg, myYes, myNo, cancel) { var confirmBox = $("#confirm"); confirmBox.find(".message").text(msg); confirmBox.find(".yes, .no, .cancel").unbind().click(function() { ...
Read MoreWhy does the JavaScript void statement evaluate an expression?
The JavaScript void returns an expression to remove the side effect and return the undefined primitive value. This side effect may occur while inserting expression in a web page.Let’s see an example of the void. The void(0) can be used with hyperlinks to obtain the undefined primitive value, ExampleLive Demo Understanding JavaScript void(0) Click me not once, but twice. We used JavaScript:void(0) above to prevent the page from reloading when the button is clicked the first time.The code will ...
Read MoreHow to deal with floating point number precision in JavaScript?
To handle floating point number precision in JavaScript, use the toPrecision() method. It helps to format a number to a length you can specify.ExampleLive Demo var num = 28.6754; document.write(num.toPrecision(3)); document.write(""+num.toPrecision(2)); document.write(""+num.toPrecision(5)); Output28.7 29 28.675
Read More