In Javascript you can write
if (condition){
console.log("")
}
as
condition && console.log("")
is there a similar syntax in koltin?
Unlike Javascript, kotlin is strictly typed. Both side of the &&
operator must be a Boolean
. You can do some meaningless equality check to achieve this, but it just makes things less readable. For examples:
condition && (println("Hello, world!") == Unit)
or
condition && (println("Hello, world!") == null)
Even ternary operator (c?a:b
) is removed in kotlin and they suggest using if(c) a else b
. So just stick with the if
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With