Question: Can anybody give some sample code to read and write a file using JavaScript?

Answer: 
Writing this answer for people who wants to get a file to download with specific content from javascript. I was struggling with the same thing.

```
const data = {name: 'Ronn', age: 27};              //sample json
const a = document.createElement('a');
const blob = new Blob([JSON.stringify(data)]);
a.href = URL.createObjectURL(blob);
a.download = 'sample-profile';                     //filename to download
a.click();

```

Check Blob documentation here - [Blob MDN](https://developer.mozilla.org/en-US/docs/Web/API/Blob)
> 
> There are two ways to read and write a file using JavaScript
> 
> 
> 

1. Using JavaScript extensions
2. Using a web page and Active X objects