Posts

Showing posts from August, 2020

Day 5 : JavaScript Closures

Image
In this blog, we are going to understand the closure concept in JavaScript. Closures in JavaScript : The closures are the important and some what complex concept in JavaScript. Before we go to closures we have to known about life of variables and scopes in JavaScript. Life of variables : 1) Global variables -                     Global variables have long lives. They are created at the beginning of the program and they live until the page or program is discarded.  2) Local variables -                      Local variables have short lives. They are created when the function is invoked and deleted when the function is finished. Scope : As we all know we can’t get data from an outside scope. JavaScript doesn’t have the public, private, protected access modifiers. For security or accessibility in JavaScript we use closures. Every closure has three scopes: Local scope, Ou...

Day 4 : JavaScript Shadowing

Image
Shadowing in JavaScript :                     Simply shadowing means exact copy of anything. In Programming, when a function or variable declared within inner class has same name as function or variable declared in outer class then shadowing occurs. So their are two concepts:   Variable Shadowing Function Shadowing We can say that the outer variable or function is shadowed by the inner variable or function. We can also say that the inner variable or function is mask of outer variable or function. Variable Shadowing: Example : Output: In above program, variable a declared in outer scope has value 10 and redeclared in inner  scope has value 5.Because of shadowing it shows inner scope value after function call. If we display the variable a in outer class then it shows 10.                                        i.e    ...

Day 3 : JavaScript

Image
 Data Types of JavaScript:  In JavaScript, their are three data types present i.e number, string and boolean. As we all know JavaScript is a dynamic language, means one variable can hold different datatypes.                    Example :                                      var x;                                      x=10;              //number                                      x="Hello"      //string                     // In above eg. the x holds number as well as string but shows string.                 ...

Day 2 : Undefined and Hoisting - JavaScript

Image
  Undefined : As we all know JavaScript is a interpreted language i.e line by line compilation or JIT (just-in-time) compilation done here. When variable is declared but not defined or assigned any value then variable returns undefined value. The methods also returns undefined value when the variable declared for it does not have assigned value. Example for undefined type: Output : From above example we know that when JavaScript has no defined value for variable then it shows undefined. May you think that why it not shows error?  It is because of hoisting.Hoisting is important concept in JavaScript which we will study later.  Is null and undefined are same? No, the null and undefined are two different entities in JavaScript. The Null is a value that can be assigned to variable and it "shows no value" where the variable is said to be Undefined if it is declared but "no value is assigned to it". The Null is the keyword in JavaScript which gives no value where as Undef...

Day 2 : Global Pollution - JavaScript

Image
    Var for declaration :                      ·          In JavaScript, first we declare the variable then initialize it. ·          The compiler knows the datatype only after initialization.   Global Pollution : ·          Before global pollution we have to understand about the reference error. ·          If variable is not declared in respected scope then compiler shows the reference error. ·          Example of reference error:   Output:   If we don’t give var keyword to variable then it will access the value globally i.e called as global pollution. Var respects scope, without var keyword varia...

Day 1 : JavaScript

Image
Basics of JavaScript Now-a-days , JavaScript is the mostly used language. So we are going to understand important concepts in detail. First we are.going to start with basics. History :  JavaScript was invented by Brendan Eich in 1995. ECMAScript is the official name of the JavaScript.Therefore whenever we refer versions of JavaScript , we say ECMAScript. The current version of JavaScript is ECMAScript 5 and ECMAScript 6 is developing. JavaScript did not have exception handling until ECMAScript 3. This version explains why language automatically converts values. JavaScript uses semicolon at end of statement. Introduction : JavaScript is a object-oriented , dynamic programming language. The JavaScript code should be written in script. JavaScript is a case-sensitive language. Datatypes are infered(Implicit i.e right side data is checked first) in JavaScript. Example of JavaScript : Program : Output :              ...