local storage and performance Flashcards
How are cookies set and stored?
The server sends the cookie in the HTTP server response header as a name = value pair. The browser stores the cookie and sends it back in the request header in the same way.
What is a way to get around the limitation on number of cookes that a domain can send?
Use subcookies. Rather than name = value, use name = name1=value1&name2=value2…
How do you write a try/catch statement?
try { if ( a ) { throw errorObject }; } catch (error) { // error arg is required doSomething( ); } finally { // optional }
localStorage vs. IndexedDB
localStorage is synchronous and string only storage, intended mainly for smaller amounts of data. It will block page loading.
IndexedDB is more database-like; asynchronous, for greater amounts of data
How is an object represented in json (4 key elements) ?
Like a javascript object, but with a few key differences: key must be in quotes; no comma after last pair; no trailing semicolon; must use double quotes.
When is try-catch statement most useful?
For handling an error that is out of your control —for example, when dealing with a library whose code you can’t touch.
When should you catch errors vs. when should you throw errors using throw new Error( )?
Catch errors only if you know what to do — you want to prevent browser from doing its default thing.
Throw errors if you don’t know what to do. Purpose is to provide information about why error occurred.
What is the most bomber way to do type detection (e.g. to determine if a value is an array or function or regexp or whatever)?
Object.prototype.toString.call ( valueToTest );
This will return a string in format of “[Object NativeConstructorName “]; // e.g. [Object Array]
JSON allows representation of what types of values?
Simple values, objects (string-value mappings), and arrays. It doesn’t more complex data types like functions or regular expressions.
What are the JSON object’s methods? And what do they do?
JSON.stringify(someObj) serializes an object into a JSON string.
JSON.parse(someJSON) turns a JSON string into a javascript value.
What arguments does JSON.stringify() take?
The object to serialize; a filter, which can be an array or a function; indentation amount.
What is the execution context in javascript?
It can be thought of as an object with three properties – what are they?
An execution context is created every time a function is called (there’s also one for evals, withs, and global). 1. variable object; 2. scope chain; 3. ‘this’ object.
How can you filter what data gets serialized into a JSON string?
The second stringify argument can be an array of keys (e.g. [“title”, “author”]). Only those keys will be serialized.
Or it can be a function that can be more nuanced or allow you to make changes.
What is ECMA5 definition of a property?
An association between a name and a value that is part of an object
In other words, part of an object.
What is ECMA5 definition of a variable?
There isn’t one. But it seems to be something like this:
An association between a name and a value that is part of an execution context. It belongs to a VariableObject.