I have a function which parses the address components of the Google Maps API JSON
and then returns the city / locality / route name.
The getAddre
For empty strings you can use !
:
var foo = 'yo';
console.log(!foo);
var foo = null;
console.log(!foo);
And for the ?
you asked about, it's the Conditional (ternary) Operator, the syntax is condition ? if true : if false
you can use it as follows:
var foo = 'yo';
console.log('1 : ' + (!foo ? 'Null' : 'Not Null'));
console.log('2 : ' + (foo === null ? 'Null' : 'Not Null'));
console.log('3 : ' + (foo == null ? 'Null' : 'Not Null'));
var foo = null;
console.log('1 : ' + (!foo ? 'Null' : 'Not Null'));
console.log('2 : ' + (foo === null ? 'Null' : 'Not Null'));
console.log('3 : ' + (foo == null ? 'Null' : 'Not Null'));