How to name variables in JavaScript?

Rahul Sharma
Published on 16-Jan-2018 06:06:57
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.While naming your variables in JavaScript, keep the following rules in mind.You should not use any of the JavaScript reserved keywords as a variable name. ... Read More

How to replace all occurrences of a string in JavaScript?

Johar Ali
Published on 16-Jan-2018 06:02:36
To replace occurrences of a string in JavaScript, use the replace() method −<html>    <body>       <script>          var str1 = 'John loves studying. He loves Football too!';          var str2 = str1.replace(/loves/g, "likes");          document.write(str2);       ... Read More

How is JavaScript an untyped language?

Lakshmi Srinivas
Published on 23-Jan-2018 09:49:54
JavaScript is an untyped language. This means that a JavaScript variable can hold a value of any data type. It does not work like C, C++, Java; datatypes like int, char are not needed here.To declare variables in JavaScript, you need to use the var keyword. Whether it is a ... Read More

How to write Python regular expression to get zero or more occurrences within the pattern?

Rajendra Dharmkar
Published on 03-Jan-2018 13:37:58
*      An asterisk meta-character  in a regular expression indicates 0 or more occurrences of the pattern to its leftThe following code matches and prints the zero or more occurrences of the pattern '\w' in the string 'chihua huahua'Exampleimport re s = 'chihua huahua' result = re.findall(r'\w*', s) print ... Read More

How is JavaScript an interpreted language?

Monica Mona
Published on 23-Jan-2018 06:52:47
JavaScript is 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. ... Read More

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

Published on 16-Jan-2018 05:45:59
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 −<html>    <body>       <script>          var rank = ... Read More

Variable Hoisting in JavaScript

Rahul Sharma
Published on 16-Jan-2018 05:44:39
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, ... Read More

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

Johar Ali
Published on 14-Jan-2018 07:29:38
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 DOM is loaded and before the page contents are loaded.$(document).ready(function() {    alert(“Document loaded successful!"); });ExampleIn JavaScript, to achieve the same ... Read More

How to validate decimal numbers in JavaScript?

Published on 12-Jan-2018 12:41:28
To validate decimal numbers in JavaScript, use the match() method. It retrieves the matches when matching a string against a regular expression.ExampleYou can try to run the following code to validate decimal numbers −<html>    <body>       <script>          var str = "1.5";     ... Read More

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

Rahul Sharma
Published on 12-Jan-2018 12:39:32
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 −<html>    <body>       <script>          <!--             var age = 20;           ... Read More