Appropriate Key-Value Pair on Object

Hello campers,
I just did a Redux challenge and I realize that the addToDo function takes an argument called todo which then added to the object that will be returned.

What I want to know is by the way the parameter is added to the object, is it supposed to be a key-value pair, or consider as a key without value? Because what I did was passing a string "Reading" to the function and the program still works and the challenge is solved. Is it supposed to be key-value pair like todo: "Reading" or something other than that?

Any answer would be appreciated. Thank you.


const ADD_TO_DO = 'ADD_TO_DO';

// A list of strings representing tasks to do:
const todos = [
'Go to the store',
'Clean the house',
'Cook dinner',
'Learn to code',
];

const immutableReducer = (state = todos, action) => {
switch(action.type) {
  case ADD_TO_DO:
    // Don't mutate state here or the tests will fail
    return
  default:
    return state;
}
};

const addToDo = (todo) => {
return {
  type: ADD_TO_DO,
  todo
}
}

const store = Redux.createStore(immutableReducer);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36.

Challenge: Never Mutate State

Link to the challenge:

if you mean this, it’s a JavaScript feature, you will have a key-value pair with the variable name as key and the variable value as value of the pair

let myVar = "I'm a variable";
let myObj = {myVar};
console.log(myObj); // {myVar: "I'm a variable"}
2 Likes

Thanks for the reply @ilenia, its really help me out. I’m not sure if it already teached on the Javascript curriculum, and if I it did, then I must’ve forgot it. Thank you.