If you don't mean JavaScript running in a web browser, then yes, it could be done.

Actually there is a database available inside JavaScript. It was supposed to be part of the new HTML5 standard under the name "Web SQL Database", but apparently this standardization effort has been stopped:

In that case you could actually use the HTML5 local storage feature too.

That would be using a database implemented by the JavaScript engine though, not implementing a database engine in JavaScript itself (which is the meaning I took away from "make a JavaScript database").