This Keyword in JavaScript

This keyword refers to an object, that object which is executing the current bit of JavaScript code. JavaScript function while executing has a reference to its current execution of any function, called this. JavaScript function while executing has a reference to its current execution of any function, called this. with this keyword, It does not matter how and where … Read more

JavaScript variables

Variable is a user given name to a memory location where user can store values and can access it using variable name. user can give any valid variable name to store data. Variables can store different types of data like integer,character,string, boolean,real values etc. Syntax

for all kind of variable we use var keyword … Read more

Getting Current URL of web page

Address bar shows current url if you want to access in javascript program then we use window.location.href Syntax

Example:

Change background color on button click in javascript

Change background color on button click in javascript is a good example of DOM manipulation. You can change the background color of any element like div, paragraph or can change the color of the HTML body. To change the background color we use style property. Let us see one by one Changing the background color … Read more

Try Catch and Finally in JavaScript

Try Catch and Finally in JavaScript is used for exception handling. The try statement tests a block of code for errors. The catch statement handles the error. The throw statement throws or creates custom errors. With final statement the code will be executed, and after try and catch, the function will return a result. Errors … Read more

JavaScript Syntax

var x, y; // How to declare variables x = 5; y = 6; // How to assign values z = x + y; // How to compute values JavaScript Keywords JavaScript keywords are some reserved words that can’t be used as identifier and are used to identify actions to be performed e.g., the var keyword tells the browser … Read more

Data Object in JavaScript

The Date object is a datatype, Date objects are created with the new Date( ), Most of “Date” methods simply allow you to get and set the year, month, day, hour, minute, second. If no arguments are provided, the constructor creates a JavaScript Date object for the current date and time according to system settings for timezone offset. … Read more

JavaScript Inclusion in HTML File

Javascript in Internal File You can place JavaScript code on HTML pages anywhere within<html> tags(within <body>tag as well as <head> tag) JavaScript code must be inside <script> tag for aninternal placement. Within <head> tag Within <body> tag External JavaScript To use JavaScript from an external file source, all JavaScript source code must be written in a … Read more

Regular Expression in JavaScript

What is a Regular Expression(RegEx)? Regular expressions/sequence of characters are patterns used to match character combinations in strings. A regEx can be a single character or a complicated pattern. Regular expressions can be used to perform text search and validation operations. Special characters in regular expressions Character Meaning ^ It Matches the beginning of an input e.g., … Read more

Global in JavaScript

Global scope is a JavaScript function Scope.Scope determines the accessibility (visibility) of variables. Variables defined inside a function are not accessible (visible) from outside the function. A global variable is declared outside the function or declared with an object. It can be accessed from any function. Declaring global variable within function To declare global variables within … Read more