how to compare two strings in javascript if condition

You could check every option. if (compare === “page1” || compare === “page2”) { Or you could use an array and check with an existential quantifier like Array#some against, like if ([“page1”, “page2”].some(a => a === compare)) { var compare = “page3”; if (compare === “page1” || compare === “page2”) { document.body.innerHTML = “github url”; … Read more

“Wrong” return type when using if vs. ternary opertator in Java

Basically it’s following the rules of section 15.25 of the JLS, specifically: Otherwise, if the second and third operands have types that are convertible (§5.1.8) to numeric types, then there are several cases: […] Otherwise, binary numeric promotion (§5.6.2) is applied to the operand types, and the type of the conditional expression is the promoted … Read more

if / else at compile time in C++?

C++17 if constexpr Oh yes, it has arrived: main.cpp #include <cassert> #include <type_traits> template<typename T> class MyClass { public: MyClass() : myVar{0} {} void modifyIfNotConst() { if constexpr(!isconst) { myVar = 1; } } T myVar; protected: static constexpr bool isconst = std::is_const<T>::value; }; int main() { MyClass<double> x; MyClass<const double> y; x.modifyIfNotConst(); y.modifyIfNotConst(); assert(x.myVar … Read more

IF() statement alternative in SQLite

For generic SQL you can use CASE: CASE is used to provide if-then-else type of logic to SQL. Its syntax is: SELECT CASE (“column_name”) WHEN “condition1” THEN “result1” WHEN “condition2” THEN “result2” … [ELSE “resultN”] END FROM “table_name” From http://www.sqlite.org/lang_expr.html section “The CASE expression” E.g. UPDATE pages SET rkey = rkey + 2, lkey = … Read more