//声明和初始化
function init() {
// 初始化变量
let name = "John Doe";
let age = 30;
let isStudent = false;
let city = "New York";
let favoriteColor = "blue";
let favoriteFood = "pizza";
let hobbies = ["reading", "swimming", "traveling"];
// 初始化数组
let array1 = [1, 2, 3];
let array2 = ["apple", "banana", "orange"];
// 初始化对象
let obj1 = {
name: "Jane Doe",
age: 25,
isStudent: true,
city: "Los Angeles",
favoriteColor: "red",
favoriteFood: "hamburgers",
hobbies: ["running", "yoga", "reading"],
};
// 初始化函数
let myFunction = function () {
console.log("Hello World!");
};
// 初始化其他东西...
return {
name: name,
age: age,
isStudent: isStudent,
city: city,
favoriteColor: favoriteColor,
favoriteFood: favoriteFood,
hobbies: hobbies,
array1: array1,
array2: array2,
obj1: obj1,
myFunction: myFunction,
};
}
// 调用 init 函数
let initResult = init();
// 输出结果
console.log("Name:", initResult.name);
console.log("Age:", initResult.age);
console.log("isStudent:", initResult.isStudent);
console.log("City:", initResult.city);
console.log("Favorite Color:", initResult.favoriteColor);
console.log("Favorite Food:", initResult.favoriteFood);
console.log("Hobbies:", initResult.hobbies);
console.log("Array 1:", initResult.array1);
console.log("Array 2:", initResult.array2);
console.log("Object 1:", initResult.obj1);
console.log("myFunction():", initResult.myFunction());
领取专属 10元无门槛券
手把手带您无忧上云