Setting Property Values Programmatically in a JSON Object
Stupid nitpick..

There's no such thing as a JSON object in Javascript, they're just objects in Javascript. JSON stands for JavaScript Object Notation - Talking about JSON objects in the context of Javascript is like saying "strawberry flavored strawberry ice-cream which is strawberry flavored." Sorry. &lt;/rant>

Best option

If this is a realistic representation of your objective then the third one is the best, fastest and most concise. Creating a function to add two numbers is a waste of space and memory. Creating a variable is also a waste of memory as it will just have to get garbage collected.

Approaches you aven't considered



class add2Numbers{
    constructor(){
        this.addend = 0;
        this.augend = 0;
        this.result = 0;
    }

    parseNum(n){ 
        return parseFloat(n); 
    }
    
    addAddend(n){
        this.addend = this.parseNum(n);
    }
    
    addAugend(n){
        this.augend = this.parseNum(n);
    }
    
    doMath(){
        this.result = this.addend + this.augend;
    }
    
    getResult(){
        return this.result;
    }
}

function insertProperty(obj, key, value){
    obj[key] = value;
}

var o = {};
var adder = new add2Numbers();
adder.addAddend(2);
adder.addAugend(5);
adder.doMath();
var result = adder.getResult();
insertProperty(o, 'sum', result);

// o now contains a property called 'sum' which contains the
// sum of the numbers 2 and 5
console.log(o);




&lt;/sarcasm>



The point that I'm trying to make is that new programmers and even old ones for some reason spend way too much time worrying about stupid buzzwords that they completely forget about common sense. The only buzzword you need right now is K.I.S.S.

Good luck and godspeed.