Skip to content

Instantly share code, notes, and snippets.

@ajitbohra
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajitbohra/991752037a34e98194ba to your computer and use it in GitHub Desktop.
Save ajitbohra/991752037a34e98194ba to your computer and use it in GitHub Desktop.
jQuery: String & number concatenation returning NaN
//Scenario 1: String & Math calculation
"height :" + $(document).height() - $(window).height();
//Result: NaN
//Scenario 2: String & Math calculation with parentheses
"height :" + ($(document).height() - $(window).height());
//Result: Height : 1870
//Scenario 3: String without match calculation
"Height:" + $(document).height();
//Result: Height737
//Scenario 4: Match Calculation & String
$(document).height() - $(window).height() + "Height";
//Result: 1870Height
//Scenario 5: String & Match calculation (Converting math output to string)
"Height" + String($(document).height() - $(window).height());
//Result: Height:1870
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment