I know there is a way for writing a Java if
statement in short form.
if (city.getName() != null) {
name = city.getName();
} else {
name=
here is one line code
name = (city.getName() != null) ? city.getName() : "N/A";
here is example how it work, run below code in js file and understand the result. This ("Data" != null)
is condition as we do in normal if()
and "Data"
is statement when this condition became true. this " : "
act as else and "N/A"
is statement for else condition. Hope this help you to understand the logic.
name = ("Data" != null) ? "Data" : "N/A";
console.log(name);