Skip to content

Instantly share code, notes, and snippets.

View karthiks's full-sized avatar
🎯
Focusing

Karthik Sirasanagandla karthiks

🎯
Focusing
View GitHub Profile
@karthiks
karthiks / theFunctionExpression.js
Last active January 1, 2016 03:29
The Function Expression Example
/*
var [variableName] = function [functionName] (param1, param2, .., paramN) {
statements
}
*/
//Eg1:
//a function expression of an anonymous function assigned to the variable multiply
var multiply = function(x, y) {
return x * y;
};
@karthiks
karthiks / theFunctionConstructorExample.js
Created December 22, 2013 18:11
The Function constructor example
/*
Pattern:
new Function (arg1, arg2, ... argN, functionBody)
*/
//Eg:
//a function defined with the Function constructor assigned to the variable multiply
var multiply = new Function("x", "y", "return x * y;");
/*
@karthiks
karthiks / whenFunctionDeclarationCeasesToBeIt.js
Last active January 1, 2016 03:38
When a function declaration ceases to be one..
/* Eg1: */
var x = 0; // source element
if (x == 0) { // source element
x = 10; // NOT a source element
function boo() {} // NOT a source element
}
function foo() { // source element
var y = 20; // source element
@karthiks
karthiks / functionNameAndVariable.js
Created December 22, 2013 18:29
* The function name can be different from the variable the function is assigned to. They have no relation to each other. * The function name cannot be changed, while the variable the function is assigned to can be reassigned.
/* Eg.1: */
function foo() {}
alert(foo); // alerted string contains function name "foo"
var bar = foo;
alert(bar); // alerted string still contains function name "foo"
bar = "asd";
alert(bar); //alerted string is now "asd"
@karthiks
karthiks / usingFunctionName.js
Last active January 1, 2016 03:39
The function name can be used only within the function's body. Attempting to use it outside the function's body results in an error like "ReferenceError: u is not defined" or undefined if the function name was previously declared via a var statement.
/* Eg.1: */
var y = function p() {};
alert(y); // works!
alert(p); // throws an error!!
var q;
var z = function q() {};
alert(z); // works!
alert(q); // undefined
@karthiks
karthiks / functionDeclarationCreatesSameNameVariable.js
Created December 22, 2013 18:42
A function declaration also creates a variable with the same name as the function name. Thus, functions defined by function declarations can be accessed by their name in the scope they were defined in.
function r() {}; //Case of function declaration
alert(r); //works!!! outputs r serialized into a string.
@karthiks
karthiks / functionUsedBeforeFunctionDEclaration.js
Created December 22, 2013 18:47
Unlike functions defined by function expressions or by the Function constructor, a function defined by a function declaration can be used before the function declaration itself.
foo(); // alerts FOO!
function foo() {
alert('FOO!');
}
// Window Size Bookmarklet: see the size of any page to debug CSS3 media queries and adaptive layouts
// Source: http://www.josscrowcroft.com/2011/code/window-size-bookmarklet/
// javascript:(function(){var f=document,a=window,b=f.createElement("div"),c="position:fixed;top:0;left:0;color:#fff;background:#222;padding:5px 1em;font:14px sans-serif;z-index:999999",e=function(){if(a.innerWidth===undefined){b.innerText=f.documentElement.clientWidth+"x"+f.documentElement.clientHeight;}else if(f.all){b.innerText=a.innerWidth+"x"+a.innerHeight;}else{b.textContent=window.innerWidth+"x"+window.innerHeight;}};f.body.appendChild(b);if(typeof b.style.cssText!=="undefined"){b.style.cssText=c;}else{b.setAttribute("style",c);}e();if(a.addEventListener){a.addEventListener("resize",e,false);}else{if(a.attachEvent){a.attachEvent("onresize",e);}else{a.onresize=e;}}})();
// Code above is beautified below for easy reading:
(function () {
var f = document,
a = window,
b = f.createElement("div"),
<!DOCTYPE html>
<html>
<head>
<title>Test Page</title>
</head>
<body>
This is a test page :P
</body>
<!-- This script got to be at the rock bottom so that
the dom (<body> in particular) is loaded for the JS to work-->
@karthiks
karthiks / hn.java
Created February 12, 2014 10:48
Examples of Hungarian Notation
ArrayList arrlstCbosPagedDetails;
ArrayList arrlstCbosTotalDetails;
String sOperation = request.getParameter(ABCConstants.OPERATION);
int iTotalRecords = objConsolidatedBOSForm.getTotalRecords();