I noticed you said:
I have been writing javascript through courses like codecademy, treehouse and udacity, maybe it hasn’t been enough but I am not sure where else I can write javascript.
If that means you are only writing javascript code in the environments they provide on those websites you are probably going to feel constrained.
In my experience I’ve learned the most through getting my hands dirty and experimenting by playing with code in less constricting environments.
I experiment in three main places:
- Actual files on my computer (my dev environment where I run a local webserver).
- Google chrome dev tools. (Typing stuff in the console or using Snippets).
- The repl.it website.
When you don’t understand what is happening with your code start breaking it down into the smallest pieces possible and experiment with those.
For example just now I’m playing around with the Date object in the console.
If I type Date
in the console it returns ƒ Date() { [native code] }
.
Typing Date()
returns "Fri Feb 23 2018 16:49:42 GMT-0800 (Pacific Standard Time)"
Typing new Date()
returns Fri Feb 23 2018 16:50:27 GMT-0800 (Pacific Standard Time)
Hmm what’s the difference? Date()
returns a string but new Date()
returns the same but without the quotes, why is that?
typeof Date()
returns “string”
typeof new Date()
returns “object”
typeof Date
returns “function”
Maybe this generates more questions that you can pursue like what does the new
keyword do?
Explore the MDN docs but maybe the mdn docs look to complicated, too much info. Go ahead and try stackoverflow or even w3schools or look up a youtube vid, anything that helps you move forward.
Browsing through the MDN docs just now I see they have a section called Conversion Getter that shows some built in methods available to return nicely formatted strings.
let d = new Date(); // Create a new date object
let theDate = d.toDateString();
let moreDate = d.toLocaleDateString();
let theTime = d.toLocaleTimeString();
console.log(theDate); // Gives me "Fri Feb 23 2018"
console.log(moreDate); // Gives me "2/23/2018"
console.log(theTime); // Gives me "5:33:31 PM"