My code passes the test, but I’m wondering if there is a difference between using .slice() which is what FCC answer uses versus .substring. Should I stick to using .substring or is there an advantage of using .slice()?
Your code so far
function confirmEnding(str, target) {
let end = str.substring(str.length-target.length);
if (target===end){
return true;
}
else {
return false;
}
}
console.log(confirmEnding("Bastian", "n"));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36.
You got me wondering this myself…I found a stackoverflow answer that breaks down how they each work pretty well: https://stackoverflow.com/a/31910656
Actually all the answers there are pretty good haha.
Right?? I swear half the time, explanations of JS concepts just make them more confusing then they were before hahaha. I guess the real understanding comes from just messing around with them, trying different things and noting the results.