How can I call a function directly on a string?
var test = function(x){
console.log(x);
};
test();
** The above logs 'undefined' as it should.
If I try:
"test".test();
I get:
"error"
"TypeError: \"test\".test is not a function.
But test is a function. So even if I try:
var example = "test";
example.test();
I get:
"error"
"TypeError: example.test is not a function
Any help is greatly appreciated.
Stringobject and then call that method on aStringtype value, see Luke's answer.test(the global variable) is a function, butexample.testor"test".test(the string properties) are not, as your error messages state.