Java script promise then catch methods

Promise create links between producing code and consuming code.
let promise= new Promise(function(resolve, reject){

This promise constructor will contain producing code and one function pass to this constructor and automatically call as promise object created.
resolve and reject arguments automatically passed to this function by java script itself.
  1. resolve(value)
    Call when job finished with value.
  2. reject(error)
    Call when job failed with the error object.

consuming code with these methods

  1. .then()
    To consume data.
  2. .catch()
    To consume errors
  3. .finally()
    Run always


<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    // data
    var groups=[
    var products=[
        "name":"HP Laptop"
        "name":"HP Mouse"
        "name":"Dell laptop"

function loadGroup(id){
    return new Promise( (resolve, reject)=>{
        let group=groups.find(item=>{
            return == id;
    } )

function loadProducts(id){
    return new Promise((resolve, reject)=>{
        let product=products.find(item=>{
            return item.group_id == id;

    return loadProducts(


© 2016 - 2022, All Rights are Reserved.