Reputation: 36
I am facing an error that shows legacy octal literals are not allowed while working on context API in react. For reference, I am attaching a code snippet below.
const [mission, setMission] = useState({ name: "go to russia", agent: 007, accept: "Not accepted", })
Upvotes: 0
Views: 608
Reputation: 943630
A number starting with a 0
is treated as an octal instead of a decimal.
const value = 010;
console.log(value);
This can be confusing so it has been forbidden in your circumstance.
007
is the same as 7
anyway. If the leading-zero formatting is important then use a string instead (either there where you have 007
or you can use 7
there and format the number on output).
const data = { agent: "007" };
console.log(data.agent);
const format = {
minimumIntegerDigits: 3,
minimumFractionDigits: 0,
useGrouping: false
};
const data = {
agent: 7
};
console.log(data.agent.toLocaleString('en', format));
Which you use will depend on if you ever need to treat agent
as a number or not.
Upvotes: 2