#bestPractice #php #js #py
Join an array into String in (PHP, JS, PY)
Bad practice:
//python
print("a" + " " + "b)
//php
echo "a"." ".b";
Best Practice:
// js
console.log(["a", "b"].join(" "));
//python
print(" ".join(["a", "b"])
//php
echo implode(" ", ["a", "b"]);
Join an array into String in (PHP, JS, PY)
Bad practice:
//python
print("a" + " " + "b)
//php
echo "a"." ".b";
Best Practice:
// js
console.log(["a", "b"].join(" "));
//python
print(" ".join(["a", "b"])
//php
echo implode(" ", ["a", "b"]);
#bestPractice #js
How to prevent
let user = { };
Noob coders:
if(user && user.name){
console.log(user.name);
}else{
console.log("No name found in user object")
}
Pro coders:
console.log(user?.name ?? "No name found in user Object")
Pro tips by Biswa
How to prevent
Cannot read properties of undefined using ? operatorlet user = { };
Noob coders:
if(user && user.name){
console.log(user.name);
}else{
console.log("No name found in user object")
}
Pro coders:
console.log(user?.name ?? "No name found in user Object")
Pro tips by Biswa
π3π2