Front End Technology Articles

Page 542 of 652

What is the difference between a++ and ++a in JavaScript?

Krantik Chavan
Krantik Chavan
Updated on 13-Jun-2020 8K+ Views

++a returns the value of an after it has been incremented. It is a pre-increment operator since ++ comes before the operand.a++ returns the value of a before incrementing. It is a post-increment operator since ++ comes after the operand.ExampleYou can try to run the following code to learn the difference between i++ and ++i −                       var a =10;           var b =20;           //pre-increment operator           a = ++a;           document.write("++a = "+a);                       //post-increment operator           b = b++;           document.write(" b++ = "+b);          

Read More

How to use the same JavaScript in multiple content pages?

Rahul Sharma
Rahul Sharma
Updated on 13-Jun-2020 2K+ Views

To use the same JavaScript in more than one page, add the js code in an external JavaScript file. Let’s say the following demo.js is our external JavaScript file −function display() {    alert("Hello World!"); }Now add the external JavaScript file to the following HTML web page. In the same way, you can add it to multiple content page.                                          

Read More

How does the browser identify inline JavaScripts?

Johar Ali
Johar Ali
Updated on 13-Jun-2020 485 Views

Let’s say the following line we have in our HTML −Here the browser identifies inline JavaScript by detecting onclick, even when tag wasn’t available.The following are some of the suggestions for using inline JavaScripts −You should consider inline script elements such as ...) if the script only to be used for a single page.Do not use event attributes such as onclick="...", and bind event handlers using JavaScript.Use external script elements such as ) for most scripts, especially if reused between pages.

Read More

What are the rules for JavaScript's automatic semicolon insertion (ASI)?

Amit Sharma
Amit Sharma
Updated on 13-Jun-2020 373 Views

JavaScript’s automatic semicolon insertion (ASI) is to insert missing semicolons. The following statements are affected by automatic semicolon insertion −empty statement var statement expression statement do-while statement continue statement break statement return statement  throw statementThe rules are in the following specification −When, as a Script or Module is parsed from left to right: A token is encountered that is not allowed by any production of the grammar, then a semicolon is automatically inserted before the offending token only if one or more of the following conditions becomes true −Offending token is }.Previous token is ) and the inserted semicolon would ...

Read More

How to handle when JavaScript is turned off?

Johar Ali
Johar Ali
Updated on 13-Jun-2020 175 Views

Nowadays, almost every web browser supports JavaScript. If it is turned off, you can use tag. 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 an alternate text message.Example           HTML noscript Tag                                              Your browser does not support JavaScript!          

Read More

How to declare variables in JavaScript?

Rahul Sharma
Rahul Sharma
Updated on 13-Jun-2020 1K+ Views

Like many other programming languages, JavaScript has variables. Variables can be thought of as named containers. You can place data into these containers and then refer to the data simply by naming the container.Before you use a variable in a JavaScript program, you must declare it. Variables are declared with the var keyword as follows.     You can also declare multiple variables with the same var keyword as follows −     Storing a value in a variable is called variable initialization. You can do variable initialization at the time of variable creation or at a later point in ...

Read More

What is the difference between anonymous and inline functions in JavaScript?

Rahul Sharma
Rahul Sharma
Updated on 13-Jun-2020 2K+ Views

Anonymous FunctionsAnonymous, as the name suggests, allows creating a function without any names identifier. It can be used as an argument to other functions. This is how JavaScript anonymous functions can be used −var myfunc = function() {    alert(‘This is anonymous'); }Another example can be the following −setTimeout(function() {    alert('Demo'); }, 3000);Inline FunctionsAn inline function is a javascript function, which is assigned to a variable created at runtime. You can difference Inline Functions easily with Anonymous since an inline function is assigned to a variable and can be easily reused.This is how JavaScript inline functions can be used −var ...

Read More

How to write JavaScript in an External File?

Amit Sharma
Amit Sharma
Updated on 13-Jun-2020 8K+ Views

Create external JavaScript file with the extension .js. After creating, add it to the HTML file in the script tag. The src attribute is used to include that external JavaScript file.If you have more than one external JavaScript file, then add it in the same web page to increase performance of the page.Let’s say the following new.js is our external JavaScript file −function display() {    alert("Hello World!"); }Now add the external JavaScript file to the HTML web page −                                      

Read More

Why prefer to put JavaScript in the footer of an HTML page?

Rahul Sharma
Rahul Sharma
Updated on 13-Jun-2020 922 Views

With JavaScript, you can put JavaScript anywhere on the page, whether inside or tag. But, it is a good practice to add JavaScript in the footer i.e. just before closing the tag. This is because −It loads script faster.It will not block any DOM content to load.It loads the web page before loading JavaScriptImproves display speedPage loads faster

Read More

Set a container that spans the full width of the screen with Bootstrap

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 12-Jun-2020 2K+ Views

Use the .container-fluid class in Bootstrap to set a container that spans the full width of the screen.You can try to run the following code to implement the container-fluid classExampleLive Demo           Bootstrap Example                                          Container fluid          Normal width          Width is 75%          Width is 50%          Width is 25%          

Read More
Showing 5411–5420 of 6,517 articles
« Prev 1 540 541 542 543 544 652 Next »
Advertisements