Tag Archives: javascript

Javascript Constructors- Why it should be used- Object Oriented Programming in Javascript

Javascript Constructors- Why it should be used- Object Oriented Programming in Javascript Mark my words! Javascript is an object oriented programming language, i.e you can create objects to solve your programming problems. In object oriented approach, you create objects that represent things in the system and you add logic for objects to behave, and then objects interact with one another ... Read More »

Avoid polluting global namespace in Javascript- IIFE (Immediately Invoked Function Expression)

Avoid polluting global namespace in Javascript- IIFE (Immediately Invoked Function Expression) Everybody says Global variables are bad, they are evil, it produces abnormal behavior. In the browser environment everything you load is in a single space. An HTML page may be linked to 1, 2, or 10 JS files. Each JS file may contain code that is written by completely ... Read More »

Understanding scopes in Javascript- Function Scoping

Understanding scopes in Javascript- Function Scoping The concept of scopes are in every language. A scope dictates a portion of program where a particular variable is accessible. Not all variables are accessible in every places of program. if variables are allowed access everywhere then there will be chaos. There are controlled portions in program where variables are active. In C++ ... Read More »

JavaScript function declaration syntax: var fn = function() {} vs function fn() {}

JavaScript function declaration syntax: var fn = function() {} vs function fn() {} In Javascript there are 2 ways to create functions:- function declaration:- function fn(){ console.log("Hello"); } fn(); This is very basic, self-explanatory, used in many languages and standard across C family of languages. We declared a function defined it and executed it by calling it. What you should ... Read More »

forEach method in Arrays – Functional Programming in Javascript Part 3

forEach method in Arrays – Functional Programming in Javascript Part 3 In Javascript arrays are objects. It has a method forEach(fn) that takes function as argument and executes it for each element of the array. This function can have element of the array, index and array itself as argument. var myArray=[10, 20, "Hello", {}]; var myFunction=function(item, index, array){ console.log("For an ... Read More »

Function expression and Anonymous Function expression – Functional Programming in Javascript Part 1

Function expression and Anonymous Function expression – Functional Programming in Javascript Part 1 Most of us know how to create a function using function declaration in javascript. function hello(){ //some code } To execute above function we just need to call the function by writing hello(). What if I say that javascript provides flexibility in creating functions using another approach ... Read More »

Secrets of Javascript Arrays

Secrets of Javascript Arrays Arrays are a common structure in many languages, Its a sequence of values that you wanna access in an indexed based way. Let’s define an array. var myArray=[100,200,300]; A point to note that Javascript arrays are zero based(well ofcourse nothing new!). But what’s the secret. Let’s raise the curtains. What if I say to calculate the ... Read More »

type coercion and === operator in javascript

type coercion and === operator in javascript Type coercion is where you have variables declared & assigned to a value and you are operating on those variables. There are certain points of time where the interpreter will have to do automatic type conversions to equivalent value of the other operands type for you in order to make operations work. Type ... Read More »