- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10711 Articles for Web Development
3K+ Views
Yes, you can use a JavaScript variable before it is declared, with a technique called hoisting. The parser reads through the complete function before running it. The behavior in which a variable appears to be used before it's declared is known as hoisting. For example, the following, rank = 5; var rank; The above works the same as the following − var rank; rank = 2; Hoisting in JavaScript, allows us to declare variables, functions, or classes that are moved to the top of the scope preceding the execution of the code regardless of whether their scope ... Read More
209 Views
The Boolean object represents two values, either "true" or "false". If value parameter is omitted or is 0, -0, null, false, NaN, undefined, or the empty string (""), the object has an initial value of false.The new Boolean() is used to create a new object. Use the following syntax to create a boolean object.var val = new Boolean(value);ExampleLet us see an example of toString() method, which returns a string of either "true" or "false" depending upon the value of the object − JavaScript toString() Method var flag = new Boolean(false); document.write( "flag.toString = " + flag.toString() );
514 Views
A boolean variable in JavaScript has two values True or False.ExampleYou can try to run the following code to learn how to work with Boolean variables − 35 > 20 Click for result function myValue() { document.getElementById("test").innerHTML = Boolean(35 > 20); }
27K+ Views
JavaScript is an untyped language. This means that a JavaScript variable can hold a value of any data type. To declare variables in JavaScript, you need to use the var, let, or const keyword. Whether it is a string or a number, use the var, let, or const keyword for its declaration. But for declaring a string variable we had to put the string inside double quotes or single quotes.Here’s how you can declare strings in JavaScript -var name = "David"; var subject = "Programming";ExampleYou can try to run the following code to learn how to declare strings in JavaScript ... Read More
5K+ Views
JavaScript is untyped language. This means that a JavaScript variable can hold a value of any data type. To declare variables in JavaScript, you need to use the var keyword. Whether it is a number or string, use the var keyword for declaration.Here’s how you can declare numbers in JavaScript −var points = 100; var rank = 5;ExampleYou can try to run the following code to learn how to declare number in JavaScript −
179 Views
Before beginning with the difference, let’s learn what are Primitive Datatypes. Primitive defines immutable values and introduced recently by ECMAScript standard.JavaScript allows you to work with three primitive data types, Numbers, eg. 3, 310.20 etc.Strings of text e.g. "This text string" etc.Boolean e.g. true or false.JavaScript also defines two trivial data types, null and undefined, each of which defines only a single value. In addition to these primitive data types, JavaScript supports a composite data type known as the object.After datatypes, let us discuss about Objects:Objects In JavaScript, objects are considered a collection of properties. Identify properties using key values. It ... Read More
443 Views
The following are the difference between inline JavaScript and external file −External scriptsThe browser stores the external script once it is downloaded for the first time. If it is to be referenced again, then no additional download is needed.This reduces download time and size.The async and defer attributes have an effect. If these attributes are present the script will change the default behavior.Inline scriptsInline Scripts are executed immediately.It gets loaded instantly and there is no need to trigger another request.The async and defer attributes has no effect.Inline Scripts are more useful for server-side dynamic rendering.Read More
988 Views
To avoid multiple server requests, group your JavaScript files into one. Whatever you use for performance, try to minify JavaScript to improve the load time of the web page.If you are using single page application, then group all the scripts in a single file.If you are using multiple files, then minify all of your scripts and separate them into categories.example - Place JavaScript to be used in every page. This can be the core script of the file. - Place your plugins hereRest, add other scripts in a JavaScript file. It’s good to maintain it in different files.Read More
370 Views
Page load time gets affected with JavaScript files and code. If you are not optimizing JavaScript files then the page load time will increase, which shouldn’t happen. Minify the JavaScript code to decrease the page load time.Also, cache JavaScript file for better results. For better performance, use inline and external JavaScript properly. Try to use external JavaScript file if you want to add the same script in multiple pages.External scriptsThe browser stores the external script once it is downloaded for the first time. If it is to be referenced again, then no additional download is needed.This reduces download time and ... Read More