Javascript Articles

Page 527 of 534

What is a fat arrow function in JavaScript?

Samual Sam
Samual Sam
Updated on 13-Sep-2019 701 Views

Fat arrow function as the name suggests helps in decreasing line of code. The syntax => shows fat arrow. This also avoids you to write the keyword “function” repeatedly.Here’s the syntax:argument => expressionUse the following for more than one argument:(argument1 [, argument2]) => expressionLet’s compare a function with and without fat arrow:Function in JavaScriptvar rank = [7,8,9]; var display = rank.map(function(num) {    return num * num; });Fat Arrow function in JavaScriptvar rank= [7,8,9]; var display = rank.map((num) => num*num); document.write(arr)Arrow function definitely reduces the code lines.

Read More

How to unset a JavaScript variable?

Sai Subramanyam
Sai Subramanyam
Updated on 13-Sep-2019 18K+ Views

To unset a variable in JavaScript, use the undefined. After that, use delete operator to completely remove it.Let’s try the code snippet again.var str = “Demo Text”; window.onscroll = function() {    var y = this.pageYOffset;    if(y > 200) {       document.write(nxt);       nxt = undefined; // unset      delete(nxt); // this removes the variable completely      document.write(nxt); // the result will be undefined } }

Read More

What is the best way of declaring multiple Variables in JavaScript?

Amit Sharma
Amit Sharma
Updated on 13-Sep-2019 257 Views

Definitely, the following way of declaring multiple variables is more efficient:var variable1 = 5; var variable2 = 3.6; var variable3 = “Amit”;Suppose you need to add, remove, or update a variable, then you can easily do it.But with the following method, you need to do more changes. For example, on removing a variable, you need to remove the semi-colon. If it’s the first, then you need to add var to the second variable.var variable1 = 5, variable2 = 3.6, variable3 = “Amit”

Read More

Which data is stored in var and how its content is changed in JavaScript?

Amit Sharma
Amit Sharma
Updated on 13-Sep-2019 128 Views

JavaScript variables are not typed but their values do have a type. The same variable can be assigned new values. Example             var a;      document.write(typeof a+"\r");      a = true;      document.write(typeof a+"\r");      a = 5;      document.write(typeof a+"\r");      a = "web";      document.write(typeof a+"\r");       

Read More

How to give a warning for Non-JavaScript Browsers?

Giri Raju
Giri Raju
Updated on 12-Sep-2019 303 Views

To let users know about non-JavaScript web browsers, use the tag. The HTML tag is used to handle the browsers, which do recognize tag but do not support scripting. This tag is used to display alternate text messageHere’s an example,           HTML noscript Tag                                              Your browser does not support JavaScript!          

Read More

How to detect if JavaScript is disabled in a browser?

radhakrishna
radhakrishna
Updated on 12-Sep-2019 7K+ Views

To detect if JavaScript is disabled in a web browser, use the tag. The HTML tag is used to handle the browsers, which do recognize tag but do not support scripting. This tag is used to display an alternate text message.Here’s an example,           HTML noscript Tag                                                    Your browser does not support JavaScript!          

Read More

What is the difference between comments /*...*/ and /**...*/ in JavaScript?

radhakrishna
radhakrishna
Updated on 12-Sep-2019 704 Views

/*…*/ and /**…*/ are multi-line comments. The following is a multi line comment in JavaScript./*    * This is a multiline comment in JavaScript    * It is very similar to comments in C Programming */The following example shows how to use multi-line comments in JavaScript.     The comment /** */ is for  PHPDocumentator ,  which is used to make automatic documentation.

Read More

Why is JavaScript case sensitive but HTML isn't?

varun
varun
Updated on 12-Sep-2019 597 Views

A script is in plain text and not just markup like HTML, which is case insensitive. In JavaScript, the while keyword should be "while", not "While" or "WHILE". Case sensitivity is important since it is closely related to HTML, but some methods and events are mentioned differently. JavaScrip has a strict syntax to process the client-side-scripts written in JavaScript.Some tags and attributes in HTML have the same name as JavaScript objects and properties. In HTML, the attribute and tag names are case-insensitive. The close association of HTML and JavaScript can lead to confusion, so case sensitivity is more important in ...

Read More

What is the difference between single-line and multi-line comments in JavaScript?

varma
varma
Updated on 12-Sep-2019 702 Views

Single Line commentThe following is a single line comment in JavaScript. Any text between a // and the end of a line is treated as a comment and is ignored by JavaScript.// This is a comment. It is similar to comments in C++Multi-Line commentThe following is a multi-line comment in JavaScript./*    * This is a multiline comment in JavaScript    * It is very similar to comments in C Programming */

Read More

Do we need to use semicolons in JavaScript?

varun
varun
Updated on 12-Sep-2019 260 Views

In JavaScript, Semicolons are optional. Simple statements in JavaScript are generally followed by a semicolon character, just as they are in C, C++, and Java. JavaScript, however, allows you to omit this semicolon if each of your statements is placed on a separate line. It is a good programming practice to use semicolons.For example, the following code could be written without semicolon.     But when formatted in a single line as follows, you must use semicolons −    

Read More
Showing 5261–5270 of 5,339 articles
« Prev 1 525 526 527 528 529 534 Next »
Advertisements