Please help me write this JavaScript function. Thank you very much! function name: defaults(target, source) Assigns properties of source object to the target object for all properties that are not...




  1. Please help me write this JavaScript function. Thank you very much!







    function name: defaults(target, source)


    Assigns properties of source object to the target object for all properties that are not defined on target.


    Parameters



    • target - Any JavaScript Object

    • source - Any JavaScript Object


    Return Value


    This function does not return anything, but it does modify target.


    Examples


    const target = {};


    const source = { foo: 1, bar: 2, baz: 3 };
    defaults(target, source);


    console.log(target) // -> { foo: 1, bar: 2, baz: 3 } const target = { foo: 1, baz: 3 }; const source = { bar: 2 }; defaults(target, source); console.log(target) // -> { foo: 1, bar: 2, baz: 3 } const target = { foo: 1, baz: 3 }; const source = { foo: 4, bar: 2, baz: 5 }; defaults(target, source); console.log(target) // -> { foo: 1, bar: 2, baz: 3 } const target = { foo: 1, baz: 3 }; const source = {}; defaults(target, source); console.log(target) // -> { foo: 1, baz: 3 }



Jun 09, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here