x = ( typeof x != 'undefined' && x instanceof Array ) ? x : [];
I understand that if x is defined and it is an array it will do everything between ? and : then if undefined or it is not an array it will do []. what is []?
Does anyone know where i can get examples of how this works and other shorthand techniques or can you explain what is happening here?
I just really dont understand how it is creating an array
[]is an empty array.So if
xisundefinedor not an array, then it is set to an empty array.This is the same as:
There is more information on the Conditional (Ternary) Operator here:
http://msdn.microsoft.com/en-us/library/windows/apps/be21c7hw%28v=vs.94%29.aspx
Another useful shorthand for default arguments is:
This is set
xto7as long asx == false(i.e.xis notnull,undefined,false,''(empty string), or0)