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?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With