Front End Technology Articles

Page 585 of 652

How to append an item into a JavaScript array?

Sravani S
Sravani S
Updated on 13-Jan-2020 287 Views

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 More

How to define integer constants in JavaScript?

V Jyothi
V Jyothi
Updated on 13-Jan-2020 1K+ Views

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 More

How to generate Prime Numbers in JavaScript?

Ayyan
Ayyan
Updated on 13-Jan-2020 3K+ Views

To generate prime numbers in JavaScript, you can try to run the following codeExampleLive Demo           JavaScript Prime                        for (var limit = 1; limit

Read More

What is the difference between parseInt(string) and Number(string) in JavaScript?

V Jyothi
V Jyothi
Updated on 13-Jan-2020 310 Views

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 More

Difference between != and !== operator in JavaScript Program

Mahesh Parahar
Mahesh Parahar
Updated on 13-Jan-2020 677 Views

'!=' 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 More

Difference between "." and "#" selector in CSS

Mahesh Parahar
Mahesh Parahar
Updated on 13-Jan-2020 3K+ Views

'.' 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 More

How exactly does <script defer=“defer”> work?\\n

Samual Sam
Samual Sam
Updated on 10-Jan-2020 308 Views

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 More

How to create JavaScript alert with 3 buttons (Yes, No and Cancel)?

Prabhas
Prabhas
Updated on 10-Jan-2020 4K+ Views

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 More

Why does the JavaScript void statement evaluate an expression?

Giri Raju
Giri Raju
Updated on 10-Jan-2020 140 Views

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 More

How to deal with floating point number precision in JavaScript?

varma
varma
Updated on 10-Jan-2020 967 Views

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
Showing 5841–5850 of 6,517 articles
« Prev 1 583 584 585 586 587 652 Next »
Advertisements