To address the difference between the two:
If you just did
var data = new FormData();
data.append('hello', 'my friend');
console.log(data)
var data2 = {
"hello": "my friend"
};
And then check your dev tools you would notice that:
FormData { }
<prototype>: FormDataPrototype { append: append(), delete: delete(), get: get(), … }
append: function append()
constructor: function ()
delete: function delete()
entries: function entries()
forEach: function forEach()
get: function get()
getAll: function getAll()
has: function has()
keys: function keys()
set: function set()
values: function values()
Symbol(Symbol.toStringTag): "FormData"
Symbol(Symbol.iterator):
function entries()`<prototype>: Object { … }
Form.data() has a lot of other properties in constructor associated with methods that you can use on it, so browser treats it differently.
Last function : function entries() <prototype>: Object { … } is the same as regular object where data is being stored with getters and setters:
Object { hello: "my friend" }
hello: "my friend"
<prototype>: Object { … }
__defineGetter__: function __defineGetter__()
__defineSetter__: function __defineSetter__()
__lookupGetter__: function __lookupGetter__()
__lookupSetter__: function __lookupSetter__()
__proto__:
constructor: function Object()
hasOwnProperty: function hasOwnProperty()
isPrototypeOf: function isPrototypeOf()
propertyIsEnumerable: function propertyIsEnumerable()
toLocaleString: function toLocaleString()
toString: function toString()
valueOf: function valueOf()
<get __proto__()>: function __proto__()
<set __proto__()>: function __proto__()
Also take notice that you last creation of object converted your string 'hello' into key hello: while form data converts all keys and values into string.
So, in short this two are not the same objects.