I am stacking here everything I find out on the web which might be useful for when I am finally going to get into the magical universe of JavaScript.
Resources
- My Learn Javascript list on GitHub
- Derek Sivers’s guide
- JavaScript and JQuery, a book by Jon Duckett
- 10 best JavaScript practices recommended by Top Developers
- JavaScript, The Right Way, an open source, easy-to-read, quick reference for JS best practices, accepted coding standards, and links around the Web
- OneMonth, free with GitHub Education
Node
- oclif: The Open CLI Framework · Create command line tools your users love
Notes
- When combining stuff, the string always wins
- you can grab the content of a DOM Element by selecting it and using
innerText
textContent
is better thaninnerText
Reading and writing JSON
To read a JSON file in JavaScript, you can use the fetch()
method to get the contents of the file as a Response
object. Then, you can convert the Response
object to JSON using the json()
method.
Here is an example:
fetch('example.json')
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error))
To write a JSON file in JavaScript, you can create an object that you want to write to a file, convert it to a JSON string using the JSON.stringify()
method, and then write the string to a file using the fs
module.
Here is an example:
const fs = require('fs')
const data = {
name: 'John',
age: 30,
city: 'New York'
}
const jsonData = JSON.stringify(data)
fs.writeFile('example.json', jsonData, err => {
if (err) {
console.error(err)
return
}
console.log('Data written to file')
})
[JavaScript]: https://en.wikipedia.org/wiki/JavaScript ‘JavaScript on Wikipedia’