Javascript add Event with callback like jquery style

You can use below code in any element see the example. CustomEvent = { addListener: function(el, type, fn) { if (el.addEventListener) { CustomEvent.addListener = function(el, type, fn) { el.addEventListener(type, fn, false); }; } else if (el.attachEvent) { CustomEvent.addListener = function(el, type, fn) { el.attachEvent(‘on’ + type, fn); }; } else { CustomEvent.addListener = function(el, type,

Read More

difference between var and let with examples

Var and let both are used to store the data. Let is a new feature which is introduced in es6. if you declare anything in let then it will only available on that block. var siteVar=’Javascript-var’; let siteLet=’Javascript-es6-let’; //variable Redeclaration – You cannot redeclare let see below var siteVar=’Javascript-var-again’; let siteLet=’Javascript-es6-let-again’; //SyntaxError: Identifier ‘siteLet’ has

Read More

javascript get query string value from URL

Examples how do you get value from the query string. Javascript ES5 function getQueryString(name) { var name,regex,QueryString; QueryString=window.location.href; name = name.replace(/[\[]/, “\\[“).replace(/[\]]/, “\\]”).toLowerCase(); regex = new RegExp(“[\\?&]” + name + “=([^&#]*)”), results = regex.exec(QueryString.toLowerCase()); return results === null ? “” : decodeURIComponent(results[1].replace(/\+/g, ” “)); } Javascript ES6

hello world in javascript

Let’s create first hello world in javascript. Step1 – open notepad or any other text editor. Step2 – Save below Text in .html format. Step3 – Open that file in any browser e.g ie, chrome, firefox <!DOCTYPE HTML> <html> <script> alert( ‘Hello, World!’ ); console.log(‘Hello, World in console.’); </script> <body> <p>Your First Javascript Hello World.</p>

Read More

javascript keywords

Below is the list of the reserved word in javascript. You cannot use these words as a variable. Every word has their own definition. abstract arguments await boolean break byte case catch char class const continue debugger default delete do double else enum eval export extends false final finally float for function goto if implements

Read More

History of JavaScript/ECMAScript

ECMAScript 1 (June 1997) ECMAScript 2 (June 1998) ECMAScript 3 (December 1999) ECMAScript 4 (July 2008) ECMAScript 5 (December 2009) – Strict Mode, Object( Getter and Setter) , forEach, filter, reduce etc.. ECMAScript 5.1 (June 2011) ECMAScript 6 (June 2015) – Block scoping, Class, Module, Arrow Function, Promise etc.. ECMAScript 7 (June 2016) What is

Read More

Welcome Javascript

Welcome again, I will cover all the javascript feature with very simple examples in this blog. Hope you like this blog. Javascript Topics: Scoping var Let const Functions Function declarations and function expressions Arrow functions Generator functions Function constructors Currying IIFE closures generator functions Symbol Array Sets and Maps Regular Expressions Module Class Object Promises