bendqh1
1
In Microsoft Edge version 120.0.2210.91 (Official build) (64-bit) I try to set and get a value with the Local Storage API.
Setting
localStorage.setItem["first_example"] = 1;
1
Getting
localStorage.getItem["first_example"];
undefined
console.log(localStorage["first_example"]);
undefined
undefined
My question
Why did I get one undefined
in the getItem
command and two undefined
in the console.log
command?
Maybe you should use round brackets and not square ones?
bendqh1
3
localStorage.setItem("first_example") = 1;
Uncaught TypeError: Failed to execute ‘setItem’ on ‘Storage’: 2 arguments required, but only 1 present.
at :1:14
localStorage.setItem{"first_example"} = 1;
Uncaught SyntaxError: Unexpected token ‘{’
localStorage.setItem("first_example", 1);
bendqh1
7
Dear Dave, thanks.
localStorage.setItem("first_example", 1);
undefined
localStorage.getItem("first_example");
1
I think that that’s what I was looking for
???
Which is what you’re looking for? I don’t get the output from the undefined. You can’t output a set.
- Setters add/update a value
- Getters return a value.
bendqh1
9
Which is what you’re looking for? I don’t get the output from the undefined. You can’t output a set.
- Setters add/update a value
- Getters return a value.
I know, I meant that getting the following output from the getter:
1
Is what I was looking for
I just meant to show the entire process from start to finish (including the undefined
console output for the setter), was fine
system
Closed
10
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.