Skip to content

Instantly share code, notes, and snippets.

@PavanKu
PavanKu / markdown.md
Created August 25, 2016 08:30 — forked from jonschlinkert/markdown-cheatsheet.md
A better markdown cheatsheet. I used Bootstrap's Base CSS documentation as a reference.

Typography

Headings

Headings from h1 through h6 are constructed with a # for each level:

# h1 Heading
## h2 Heading
### h3 Heading
@PavanKu
PavanKu / this_global.js
Created December 26, 2017 05:29
Global Execution context and value of this.
function foo () {
console.log("Simple function call");
console.log(this === window);
}
foo(); //prints true on console
console.log(this === window) //Prints true on console.
@PavanKu
PavanKu / global.js
Created December 26, 2017 05:32
IIFE (Immediately Invoked Function Expression)
(function(){
console.log("Anonymous function invocation");
console.log(this === window);
})();
// Prints true on console
@PavanKu
PavanKu / strict.js
Created December 26, 2017 05:34
Strict Mode in JS
function foo () {
'use strict';
console.log("Simple function call")
console.log(this === window);
}
foo(); //prints false on console as in “strict mode” value of “this” in global execution context is undefined.
@PavanKu
PavanKu / newInstance.js
Created December 26, 2017 05:37
this in Constructor method
function Person(fn, ln) {
this.first_name = fn;
this.last_name = ln;
this.displayName = function() {
console.log(`Name: ${this.first_name} ${this.last_name}`);
}
}
let person = new Person("John", "Reed");
@PavanKu
PavanKu / parent.js
Created December 26, 2017 05:42
this inside object method
function foo () {
'use strict';
console.log("Simple function call")
console.log(this === window);
}
let user = {
count: 10,
foo: foo,
foo1: function() {
@PavanKu
PavanKu / call.js
Created December 26, 2017 05:44
this with Call and Apply
function Person(fn, ln) {
this.first_name = fn;
this.last_name = ln;
this.displayName = function() {
console.log(`Name: ${this.first_name} ${this.last_name}`);
}
}
let person = new Person("John", "Reed");
@PavanKu
PavanKu / bind.js
Created December 26, 2017 05:46
this with bind method
function Person(fn, ln) {
this.first_name = fn;
this.last_name = ln;
this.displayName = function() {
console.log(`Name: ${this.first_name} ${this.last_name}`);
}
}
let person = new Person("John", "Reed");
@PavanKu
PavanKu / ex.js
Created December 26, 2017 05:48
Example for this
function multiply(p, q, callback) {
callback(p * q);
}
let user = {
a: 2,
b:3,
findMultiply: function() {
multiply(this.a, this.b, function(total) {
console.log(total);
@PavanKu
PavanKu / global.js
Created December 26, 2017 05:49
Global value
var count = 5;
function test () {
console.log(this.count === 5);
}
test() // Prints true as “count” variable declaration happened in global execution context so count will become part of global object.