javascript undefined, null, undefined property, 0, false, ”, ==, ===, typeof

March 22, 2012

== Equals

If the two operands are not of the same type, JavaScript converts the operands then applies strict comparison.

=== Strict equal

Returns true if the operands are strictly equal  with no type conversion.

typeof

The typeof operator returns a string indicating the type of the unevaluated operand.

typeof undefined === ‘undefined’

undefined

A variable that has not been assigned a value is of type undefined.

false

Examples of expressions that can be converted to false are those that evaluate to null, 0, the empty string (“”), or undefined.

null

null is an object. It’s type is null. Null and Undefined types are == (but not ===)

Undeclared variable

  1. /* var z*/
  2. z.x  // throws a ReferenceError

Check for undefined variable

  1. var x;
  2. if (x === undefined) {
  3.    // these statements execute
  4. }
  5. else {
  6.    // these statements do not execute
  7. }

check for undeclared variable

  1. // x has not been defined before
  2. if (typeof x === ‘undefined’) { // evaluates to true without errors
  3.    // these statements execute
  4. }
  5. if(x === undefined){ // throws a ReferenceError
  6. }

check for object property

  1. var myobj = {‘a’:’a’};
  2. myobj.hasOwnProperty(‘a’) // true
  3. var myobj2 = Object.create(myobj);
  4. myobj2.hasOwnProperty(‘a’) //false
  5. ‘a’ in myobj2 // true

check for null

  1. var c = null
  2. if (c === null) { // true
  3. }

References

http://saladwithsteve.com/2008/02/javascript-undefined-vs-null.html

http://constc.blogspot.com/2008/07/undeclared-undefined-null-in-javascript.html

http://www.mapbender.org/JavaScript_pitfalls:_null,_false,_undefined,_NaN

https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/undefined

https://developer.mozilla.org/en/JavaScript/Reference/Operators/Comparison_Operators

https://developer.mozilla.org/en/JavaScript/Reference/Operators/typeof

http://www.nczonline.net/blog/2010/07/27/determining-if-an-object-property-exists/


Connecting to Amazon EC2 Linux instance using PuTTY

March 16, 2012

EC2 private key file has extension .pem , which cannot be used by PuTTY. So we have to convert .pem to .ppk format which PuTTY accepts.  Listing the steps below to do it,

  • Download PuTTYgen – http://the.earth.li/~sgtatham/putty/latest/x86/puttygen.exe
  • Launch PuTTYgen, Using the ‘Import’ command from the ‘Conversions’ menu, load the .pem file of EC2 and press  ‘Save Private Key button’. Ignore warning about leaving the passphrase blank.  The file will be saved with .ppk extension
  • Now launch PuTTY, go to SSH panel, ‘Private key file for authentication’ load the .ppk file, and now you can use PuTTY to connect to the EC2 instance.

References:

http://clouddb.info/2009/05/17/a-quick-overview-of-putty-and-ssh-for-aws-newbies/

http://the.earth.li/~sgtatham/putty/0.62/htmldoc/Chapter8.html#puttygen-conversions

http://the.earth.li/~sgtatham/putty/0.62/htmldoc/Chapter4.html#config-ssh

http://docs.amazonwebservices.com/AWSEC2/latest/GettingStartedGuide/LaunchInstance.html


Using Ubuntu GUI remotely using NoMachine or Xming from Windows 7

March 12, 2012

Solution 1: NoMachine

Steps:

Solution 2: Xming

Steps:

Conclusion:

I am using  NoMachine, as Xming(6.9.0.31) was slow even after using SSH compression. And the latest version of Xming(7.5.0.45), which possibly has fixes for slow GUI (http://www.straightrunning.com/XmingNotes/) was not  available for free.