Found 6710 Articles for Javascript

How is JavaScript an untyped language?

Saurabh Jaiswal
Updated on 11-Aug-2022 11:46:09

1K+ Views

JavaScript is an untyped language because in JavaScript the variables can hold any data type meaning that JavaScript does not have a type declaration and when the variable is created we do not need to specify any data type unlike other programming languages like Java, C#, C++, etc. which needs int, char, float, etc. to create a variable. In JavaScript we use var, let, and const to create a variable. One of the best parts of untyped language is it gives the flexibility to reassign any type of value to a variable, it doesn't matter whether the initialized value was ... Read More

How is JavaScript an interpreted language?

Saurabh Jaiswal
Updated on 05-Jan-2023 15:31:45

4K+ Views

JavaScript is a lightweight and interpreted language, therefore, inside the context of a web browser, you don't even need to buy a compiler. You can start with a simple text editor such as Notepad. To make our life simpler, various vendors have come up with very nice JavaScript editing tools. Some of them are listed here − Microsoft FrontPage − Microsoft has developed a popular HTML editor called FrontPage. FrontPage also provides web developers with a number of JavaScript tools to assist in the creation of interactive websites. Macromedia Dreamweaver MX − Macromedia Dreamweaver MX is a very popular ... Read More

What happens when you do not declare a variable in JavaScript?

Ali
Ali
Updated on 13-Jun-2020 09:23:31

229 Views

Yes, this can be done. When you have a global scope, you can use a variable without declaring it. The following “no var” variable “points” will look at the scope chain, wince var keyword isn’t use −                    var rank = 5;          points = 50;          marks = 300;          // Anonymous function          (function() {             points = 100; //overwrites global scope points             var rank = 4; //new rank variable is created in this' function's scope             var marks = 900;             document.write(rank+"\r"); //prints 4             document.write(points+"\r"); //prints 100             document.write(marks+"\r"); //prints 900          })();          document.write('');          document.write('');          document.write(rank+"\r"); //prints 5          document.write(points+"\r"); //prints 100          document.write(marks+"\r"); //prints 300          

Variable Hoisting in JavaScript

Rahul Sharma
Updated on 13-Jun-2020 09:22:57

246 Views

When you can use a JavaScript variable before it is declared, it is done using a technique called hoisting. The parser read through the complete function before running it.The behavior in which a variable appears to be used before it is declared is known as hoisting −For example, the following,points =200; var points;The above works the same like the following −var points; ponts = 200;

What is $(document).ready() equivalent in JavaScript?

Alshifa Hasnain
Updated on 07-Mar-2025 17:39:56

3K+ Views

In this article, we will learn to achieve the same result as $(document).ready in JavaScript. In jQuery, $(document).ready() is a widely used function that ensures the DOM (Document Object Model) is fully loaded before executing JavaScript code. Different approaches The following are the approaches to achieve the same result as $(document).ready in JavaScript − Using document.readyState Using DOMContentLoaded Event Using document.readyState In jQuery, if you want an event to work on your page, you should call it inside the $(document).ready() function. Everything inside it will load as soon as the ... Read More

How to validate decimal numbers in JavaScript?

Shubham Vora
Updated on 31-Oct-2022 11:03:27

13K+ Views

In this tutorial, we will learn to validate decimal numbers in JavaScript. A number containing decimal(.) is known as a decimal number. A number comes between the two whole numbers, called decimal numbers. We use decimal numbers in calculations, progress bars, to accept input in forms, etc. A regular expression is a well-known entity for validation purposes. A Regular expression is a search pattern of characters with a specific meaning used to validate the data. It can be used for any string or number. We are going to use it for validation purposes in JavaScript. We used a simple logic ... Read More

What happens if we re-declare a variable in JavaScript?

Rahul Sharma
Updated on 13-Jun-2020 08:40:34

192 Views

On re-declaring a variable in JavaScript, the variable value still remains the same.ExampleLet’s see an example. Here, we are declaring the variable age −                              

What is a composite data type i.e. object in JavaScript?

karthikeya Boyini
Updated on 20-Apr-2022 12:36:59

3K+ Views

A data type is known as a composite data type when it represents a number of similar or different data under a single declaration of variable i.e., a data type that has multiple values grouped together. There are mainly three types of composite data types named as below −ObjectArrayFunctionIn this article, we will discuss the first type of composite data type i.e. object.ObjectAn object is a collection of properties i.e, an object can store the properties of anything in the key-value pairs. An object in javascript has keys and each key has its own value as shown in the examplelet ... Read More

What is the difference between Declaring and Initializing a variable in JavaScript?

Johar Ali
Updated on 13-Jun-2020 08:39:29

501 Views

The following is stated about declaration and initialization of a variable in ECMAScript specification −A var statement declares variables that are scoped to the running execution context’s VariableEnvironment. Var variables are created when their containing Lexical Environment is instantiated and are initialized to undefined when created. [...] A variable defined by a VariableDeclaration with an Initializer is assigned the value of its Initializer’s AssignmentExpression when the VariableDeclaration is executed, not when the variable is created.The above defines the difference:All variables are initialized with the value undefined.Variables declarations are initialized with undefined upon the initialization of their lexical environment.This initialization does ... Read More

How to check if a variable exists in JavaScript?

Amit Sharma
Updated on 13-Jun-2020 08:28:18

491 Views

To check if a variable exists in JavaScript, you need to check it against null as in the following code. Here, we’re checking the existence of variable myVar −                    var myVar = 20;          if(myVar !== undefined && myVar !== null) {             document.write("Variable exists");          }          

Advertisements