Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript - Uncaught ReferenceError: keys is not defined

Tags:

javascript

I am getting an error when I run the following command in an included script. But if I run the command from the google chrome console, it works properly.

var a = {}; console.log(keys(a)); 

Error:

 Uncaught ReferenceError: keys is not defined  

What's going on here? How can I use the keys function in an included script?

like image 545
user1767962 Avatar asked Dec 06 '12 19:12

user1767962


People also ask

How do I fix uncaught ReferenceError is not defined?

The $ sign is an alias of jQuery. The $ is not defined ReferenceError usually arises when jQuery is not loaded and JavaScript is not recognizing the $ symbol. To solve this error, first, use jQuery CDN link inside the head section or download the jQuery file and use the jQuery file link inside the head section.

What does uncaught ReferenceError is not defined mean?

The most common reason behind the error "Uncaught ReferenceError: $ is not defined" is executing the jQuery code before the jQuery library file has loaded. Therefore make sure that you're executing the jQuery code only after jQuery library file has finished loading.

What is JavaScript ReferenceError?

Reference errors in Javascript are mainly thrown when an attempt is made to reference a variable that does not exist or is out of scope. Therefore, in the majority of cases, a ReferenceError can be fixed by making sure that the referenced variable is defined correctly and is being called in the correct scope.


1 Answers

console.log(keys(a)) 

keys() is not function provided by the browser for use in your code. You probably want Object.keys()

a = {}; console.log(Object.keys(a)); 

Sometimes the console has extra functions exposed to it for ease of use debugging that aren't available in your actual code. keys() sounds like one, and copy('some text') is another.

I'm failing to find a link which lists them, sadly. But I'm quite sure there are more than those 2 functions.

like image 59
Alex Wayne Avatar answered Sep 19 '22 11:09

Alex Wayne