简体   繁体   中英

ReferenceError: ____ is not defined

I am learning JavaScript and I am stuck on this particular error for a long time now. It's nothing complicated, but I can't figure it out. The error I get is:

ReferenceError: Random is not defined

My Code:

var nameString = function(name)
{
return "Hi, I am " + name;
};

console.log(nameString(Random));

The objective of the code is basically to show "My name is Random" on the screen.

What am I doing wrong? Please help :)

  1. I don't know where you are learning Javascript from, but i would suggest: Mozilla Docs and Eloquent Javascript .
  2. That random which you are passing while calling that console.log(nameString(Random)); is a variable
  3. So, either pass it with quotes making it a string or declare the random variable and assign a value to it.

Pass 'Random' or "Random" as parameter which will take it as a string.

nameString(Random) -> Random acts as an object

nameString("Random") -> Random acts as a string

You have to write.

 nameString(Random) -> Random acts as an object nameString("Random") -> Random acts as a string

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM