Reference error


#1

nameString = function(name) {
return "Hi, I am" + " " + name
};
nameString(amrit);
console.log(nameString)

Why is this not working?


#2

You need a semi colon after this statement. ;


#3

You should pass name as string, so it should be in quotation marks:

nameString("amrit");

Also, console.log(nameString) will print function body, if you want to print result of function call, use

console.log(nameString("armit"));

#4

And these two lines?? You cannot console.log a function


#5

thank you :grinning:


#6

You're welcome. Check my edited post :slight_smile:

@bandit

Actually, you can console.log() a function. It will print it's body.

var cube = function(n) {
    return n * n * n;
};

console.log(cube(5));
// => 125
console.log(cube);
/* => function(n) {
    return n * n * n;
};
*/

#7

What he was trying to do was not console.log the body of the function. The logic behind his code was by console.log'ing
nameString it would also include spaghetti as if nameString was a variable. :slight_smile:


#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.