JavaScript, often abbreviated as JS, is a programming language and core technology of the World Wide Web, alongside HTML and CSS. As of 2023, 98.7% of websites use JavaScript on the client side for webpage behavior, often incorporating third-party libraries. All major web browsers have a dedicated JavaScript engine to execute the code on users' devices.
fetch returns an instance of the Promise class. The Promise class represents a promise. A promise is the eventual outcome of an asynchronous event. In the above example, fetchPromise represents the eventual response from the HTTP request to https://handlers.education.launchcode.org/static/weather.json. A promise can be fulfilled or rejected. When a promise is fulfilled, data is passed to the response handler function. The then method of Promise defines what will happen when the promise is fulfilled. When a promise is rejected, the error reason is returned.
.then()
on a promise
runs async
whenever you see .then, it’s a promise
.exec()
So instead of needing to nest a bunch of callbacks, you can chain a bunch of .then()
.catch()
So, can/should you always use promises instead of callbacks?
No, because it depends on if the underlying code is modern enough
Const port = 3000; const http = require(”http”); const httpstatus = require(”http-status-codes”); let app = http.createServer((request, response) =\> { console.log(”Received an incoming request.“); response.writeHead(httpStatus.OK, { ”Content-Type”: “text/html” }); let responsemessage = ” ¶ hello, nodemon. ¶ “; response.write(responseMessage); response.end(); console.log(\`Sent a response : \${responseMessage}\`); }); app.listen(port); console.log(\`The server has started and is listening on port number: \${port}\`);
Codeschool recommends javascript learning strategy:
“we recommend: Learn JavaScript and its modern ecosystem well. Adopt
Node.js, even for your client-side development, as it will bring a lot
of good tooling to help bundle your code, run linters to avoid common
syntax mistakes, run unit tests, and more. Once you’ve adopted Node.js,
be sure to bring all your depen- dencies in through NPM, including your
CSS dependencies, such as Font Awesome, Twitter Bootstrap, etc. Adopt
ES2015 (also known as ES6) and all its latest features through Babel,
which transpiles ES6 code back to ES5 JavaScript code that browsers can
understand, since they haven’t been fully upgraded to support the latest
fea- tures of JavaScript yet. Also, if you are a fan of strict typed
languages, then be sure to look into Flow and/or TypeScript.”
Everything is an object in js by way of object prototyping which I think is synonymous with inheritance