var input = $('input.name');
var display = $('p.name-display');
var nameId = 'name';
// Save and display when a new name is entered
$('form').on('submit', function handleSubmit(ev) {
ev.preventDefault();
var name = getName();
save(nameId, name);
display(name);
});
// Display the name when the page loads
display(fetch(nameId));
// An abstraction layer emerges...
function save(id, value) {
localStorage.setItem(id, value);
}
function fetch(id) {
localStorage.getItem(id);
}
function display(value) {
display.text(value);
}
function getName() {
return input.val();
}