function fibonacci(n) {
const memo = [0, 1];
const aux = (n) => {
if (memo[n] !== undefined){
return memo[n];
} memo[n] = aux(n - 1) + aux(n - 2);
return memo[n]
}
return aux(n);
}
JSON is an abbreviation for JavaScript Object Notation, which is an object format created for data exchange. Suppose you want to send the contents of an object to another program, over a network.
If the contents of this object are a message used in a messenger or chat program, how can the enxt object be transmitted.
const message = {
sender: "김코딩",
receiver: "박해커",
message: "해커야 오늘 저녁 같이 먹을래?",
createdAt: "2021-01-12 10:10:10"
}
In order for a message object to be transmitttable, the sender & receiver of the message must use the same program or have a universally readble form such as a string.
transferable condition:
Objects do not contain object contents when converted to string using type conversion. When you try a method (message.toString()) or (String(message)) on an object in JavaScript, the result is [object Object].
The way to solve this problem is to convert the object to the form of JSON or convert the JSOn to form of the object.
The method for this is:
JSON.stringify = Converts object type to JSON.
JSON.parse = Conver JSON to Object type.
let transferable Message = JSON.stringify(message)
console.log(transferableMessage) // '{"sender":"김코딩","receiver":"박해커","message":"해커야 오늘 저녁 같이 먹을래?","createdAt":"2021-01-12 10:10:10"}'
console.log(typeof(transferableMessage)) // 'string'
This process of stringifying is called serializing.
The type of object converted to JSON is string. The sender can send the object's content to someone with a serialized string of the object. So how can the receiver recreate this string message in the form of an object? You can use the method JSON.parse which does the opposit of JSON.stringify.
let obj = JSON.parse(transferableMessage)
console.log(obj) // {sender: '김코딩', receiver: '박해커', message: '해커야 오늘 저녁 같이 먹을래?', createdAt: '2021-01-12 10:10:10'}
console.log(typeof(obj)) // 'object'
The process of applying JSON.parse is called deserializing.
As sch, JSON is a format for exchanging data between different programs. JSON format is a popular format that is universally used in many languages, including JavaScript.
Now there are many ways and solutions that will allow you to increase the security and reliability of your data. The JSON programming language will be no exception to this. Click this link to learn more about JSON, the different software you can use to work with the language, and read a short tutorial on using the JSON to String Converter.