JSFiddle - React, Tailwind, and code Playground

by deepak sisodiya

JavaScript

// this keyword in javascript
/* John is running fast because "he" is trying to catch the train. 
   here he refer to John
   In a similar manner we use the this keyword to refer to an object.
*/

var alert  = function (str) {
   var st = document.createTextNode(str);
   var p = document.createElement('p');
   p.appendChild(st);
   document.querySelector('body').appendChild(p);
}

var person = {
    firstName:"deepak",
    lastName:"sisodiya",
    fullName:function() {
        return this.firstName + " " + this.lastName 
    }
}

alert(person.fullName())

var person2 = {
    firstName:"deepak",
    lastName:"sisodiya",
    fullName:function() {
        return person2.firstName + " " + person2.lastName 
    }
}

alert(person2.fullName())