I open url http://localhost where I load my js script.
Inside my js script I execute:
'use strict';
var path = window.location.pathname;
console.log(path); // it prints /
var arr = path.split('/');
if (arr.length === 0) { //actual length is 2
console.log('test'); //not executed
}
So test is not printed and my arr contains two elements and they are empty. Why does length of the array equal 2?
/. Since your input is/, youll end up with two empty strings.splitis not a strip function./to begin with, so if you split that at the slash, you are left with two “empty halves” ...