Reputation: 3085
So what I am trying to do is very simple and straightforward. Passing a String to a JavaScript function and print it as following.
brightRoom('bedroom');
Then
function brightRoom(room){
console.log("bright " . room);
}
What I get is undefined. Which I am not sure what may caused that issue.
Upvotes: 3
Views: 2095
Reputation: 16496
JavaScript's concatenation operator is a +
brightRoom('bedroom');
function brightRoom(room) {
// of course console.log("bright " + room); works
document.write("bright " + room);
}
It results in undefined because the JavaScript engine thinks that you are trying to find a property of the string called room
which of course does not exist. When you try to access a non existent property of an object undefined is returned
Upvotes: 1
Reputation: 16339
Try this
brightRoom('bedroom');
function brightRoom(room){
console.log("bright " + room);
}
Upvotes: 1