Prompt Title: useful built-in APIs and classes JS

Created 1 year ago
Votes 0
Views 383 times
0

Prompt Detail:

Sure, there are many more useful built-in JavaScript APIs and classes. Here are some of them:

  1. Fetch API: The Fetch API provides an interface for fetching resources (including across the network). It's more powerful and flexible than the older XMLHttpRequest.

    javascript
    fetch('https://api.example.com/data', { method: 'GET' }) .then(response => response.json()) .then(data => console.log(data)) .catch((error) => console.error('Error:', error));
  2. Promise: A Promise is an object representing the eventual completion or failure of an asynchronous operation. It's used for asynchronous computations and can help to avoid callback hell.

    javascript
    let promise = new Promise(function(resolve, reject) { // Do something, and call resolve if successful, reject if not }); promise.then(value => console.log("Success: ", value)).catch(error => console.log("Failed: ", error));
  3. Array: Array is a global object that is used in the construction of arrays. It has many useful methods like map(), reduce(), filter(), forEach(), sort(), etc.

    javascript
    let array = [1, 2, 3, 4, 5]; let squares = array.map(x => x * x); console.log(squares); // [1, 4, 9, 16, 25]
  4. Math: The Math object has properties and methods for mathematical constants and functions.

    javascript
    console.log("Pi is " + Math.PI); console.log("The square root of 16 is " + Math.sqrt(16));
  5. Set: The Set object lets you store unique values of any type, whether primitive values or object references.

    javascript
    let mySet = new Set(); mySet.add(1); mySet.add('some text'); mySet.add({a: 1, b: 2}); console.log(mySet.size); // 3
  6. Map: The Map object holds key-value pairs and remembers the original insertion order of the keys. Any value may be used as either a key or a value.

    javascript
    let myMap = new Map(); myMap.set('name', 'John'); myMap.set('age', 30); console.log(myMap.get('name')); // John console.log(myMap.size); // 2
  7. Date: The Date object represents a date and time functionality in JavaScript. It allows you to get the current date and time, store a date in a variable, and perform all sorts of operations with dates.

    javascript
    let now = new Date(); console.log(now.toString());

These are just some of the many built-in APIs and classes in JavaScript. Each has its own use cases and are extremely useful for different scenarios.

avatar
PLAYER
Shared 1 prompt
Created 1 year ago
  • Muchas gracias. ?Como puedo iniciar sesion? - mdmjfwrwqk - 1 month ago

Leave a Comment

Related Tag Prompts

72
0
JavaScript Jedi
1 year ago 2023-02-14 06:35:19 AIPRM
0
2
Learning Programming Basics.
1 year ago 2023-03-08 15:06:52 pawan
0
0
first class function
1 year ago 2023-03-08 16:15:57 Dilshod
0
0
priority API to Monday
1 year ago 2023-03-09 03:17:08 Moti
0
0
props drilling
1 year ago 2023-03-09 03:28:27 anik
0
0
react query
1 year ago 2023-03-09 10:07:32 rakib
0
0
Java GUI quadratic solver
1 year ago 2023-03-10 18:43:18 Xa3ap
0
0
0
0
Javascript to-do list app
1 year ago 2023-03-13 03:18:54 Simon
0
0
Django API for Todo
1 year ago 2023-03-18 17:45:33 AbdAlmjed
0
0
javascript滑块
1 year ago 2023-03-21 08:41:21 QingTool
0
0
This in odoo
1 year ago 2023-03-22 18:11:34 nqvinh
0
0
OpenAI endpoint for relevant notes.
1 year ago 2023-03-26 07:44:40 Tali
0
0
GatsbyJS Image Swap.
1 year ago 2023-03-30 12:59:59 Ilyas Gosling
0
0
0
0
Google Sheets SMS Script
1 year ago 2023-04-03 16:53:35 ben