Beginner
Introduction to Objects in JavaScript
Description
In JavaScript, objects are used to store related data and functions.
They consist of key-value pairs, where each key (also called a property) maps to a specific value.
In this challenge, you will create a simple person object that contains basic details about a person, such as their name and age.
Example Object Structure:
const person = {name: "Alice",age: 25};
Your task is to complete the function createPerson, which should take a name and age as parameters and return an object with those properties.
Example usage:
console.log(createPerson("John", 30)); // Expected output: { name: "John", age: 30 }console.log(createPerson("Emma", 22)); // Expected output: { name: "Emma", age: 22 }
Constraints
- The name parameter will always be a string.
- The age parameter will always be a number.
- The function should return an object with the properties name and age.
Did you know?
JavaScript was originally called "LiveScript" before being renamed to JavaScript.
Test Cases
Input:
"John"
Expected Output:
{ "age": 30, "name": "John" }