Hoisting in JavaScript

One of the key concept of every programming language is the Scope. In JavaScript, variable and function scoping is a little bit different and so cool! you can have multiple var (variable) in a function, All of them run well if you declare at the top of the function. (althought you wont get any kind of error if you declare at the end of the function) For example:

  1. console.log(variable);    // undefined
  2. Var variable="something";

Now, notice about the following code:

  1. var x = "something ";
  2. ... Continue

Object Literals and benefits in java scripts

JavaScript, by default does not come with built-in namespace or class but as it's extremely a flexible language you can create namespace in JavaScript by object literals. Based on wikipedia definition "literal is a notation for representing a fixed value in source code."  you can simply create Object literal by using: 

  1. A colon which separates the property name from ... Continue

Prototypes in JavaScript

JavaScript is a prototypical based language. In JavaScript objects are pairs of keys and values and these keys are Strings. Rather than keys and values, JavaScript objects have one another attribute called prototype which is a pointer to another objects . prototype property allows you to add properties and methods to an object.

 In regular form We can add a property to an object using Object.defineProperty like this:

  1. var obj = new Object.create(null);
  2. Object.defineProperties(obj, 'Name', { age: "24", propertyI... Continue

JavaScript Variables

Variables store information so that it can be used later! Like many other programming languages, JavaScript has variables. JavaScript variables can hold a value of any data type. A variable's value can change during the script.

  1. Var name;
  2. Var age;
  3. Var x,y,z;

Note: If you try to assign a value to a non-existent variable, JavaScript will create the variable for you.

You can refer to a variable by name to see its value or to change its value. The value type of a variable can change during the execution of a pr... Continue