JS typeof returns string undefined