/******************************************/
console.log('console testing.');
a = 5;
var b = null;
/******************************************/
functionDeclaration();
//Uncaught ReferenceError: functionExpression is not defined
//functionExpression();
function functionDeclaration(){
console.log('from function declaration');
}
functionExpression = function(){
console.log('from function expression');
}
functionDeclaration();
functionExpression();
console.log('functionDeclaration.name =', functionDeclaration.name);
console.log('functionExpression.name =', functionExpression.name);
/*****************************************************/
//Uncaught ReferenceError: function1 is not defined
//function1();
//Uncaught ReferenceError: function2 is not defined
//function2();
function1 = function function2(){
console.log('from function1 = function function2');
//function1 visible here
//function2 visible here
}
//console.log(function1 === function2);
function1();
//Uncaught ReferenceError: function2 is not defined
//function2();
/***********Javascript has no classes********/
/***********In Javascript everything is object********/
var person1 = {
firstName : 'Nilesh',
lastName : 'Injulkar',
age : 23,
greet : function(greeting){
//this is required to access properties eg. firstName
var temp = null;
console.log(greeting, this.firstName, this.lastName);
}
}
console.log(person1.firstName);
person1.greet('Namaste');
var person2 = new Object();
person2.firstName = 'Nilesh';
person2.lastName = 'Injulkar';
person2.age = 23;
person2.greet = function(greeting){
//requires this
console.log(greeting, this.firstName, this.lastName);
}
console.log(person2.firstName);
person2.greet('Shubhprabhat');
//Object constructor
//using function inside
function Person(firstName, lastName, age){
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
//greet method gets recreated...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.