Codes
Answers
let colors = ["Red", "Green", "Blue"];
console.log(colors.indexOf("Green")); // Output: 1
console.log(colors.indexOf("White")); // Output: -1
let date1 = new Date("2024-01-29T03:34:48.000Z"); // Tue Jan 29 2024 03:34:48 GMT+0000
let date2 = new Date("2024-01-29T15:00:00.000Z"); // Tue Jan 29 2024 15:00:00 GMT+0000
let date1String = date1.toDateString(); // "Tue Jan 29 2024"
let date2String = date2.toDateString(); // "Tue Jan 29 2024"
console.log(date1String === date2String); // Output: true
console.log(date1String < date2String); // Output: false
console.log(date1String > date2String); // Output: false
const originalString = "Hello, World!";
const removedCharacter = originalString.substring(0, 5) + " " + originalString.substring(7);
console.log(removedCharacter);
// Output: "Hello World!"
const number = 1234567.89;
const formattedNumber = number.toLocaleString();
console.log(formattedNumber)
// Output: "1,234,567.89"
const greet = "Hello, World!";
console.log(greet.substring(0, 5));
// Output: "Hello"
console.log(greet.slice(0, 5));
// Output: "Hello"
const greet = "Hello, World!";
const substring = greet.substring(0, 5);
console.log(substring);
// Output: "Hello"
const now = new Date();
console.log(now.getTimezoneOffset());
// Output: -330 (UTC+05:30)
const date = new Date();
console.log(date.getFullYear()); // Output: 2023
console.log(date.getMonth()); // Output: 2 (March is month 2)
console.log(date.getDate()); // Output: 25
console.log(date.getDay()); // Output: 6 (Saturday is day 6)
console.log(date.getHours()); // Output: 11
console.log(date.getMinutes()); // Output: 50
console.log(date.getSeconds()); // Output: 31
console.log(date.getMilliseconds()); // Output: 553
console.log(date.getTime());
// Output: 1679722523432 (time in milliseconds since January 1, 1970)
// #1. Create a Date object with the current date and time
let currentDate = new Date();
// #2. Create a Date object with a specific date and time
// (year, month, day, hour, minute, second)
let specificDate = new Date(2024, 0, 8, 2, 50, 2);
// #3. Create a Date object from a string
let stringDate = new Date("January 8, 2024 02:50:02");
// #4. Create a Date object from a timestamp
// ( milliseconds since January 1, 1970)
let timestampDate = new Date(1700000000000);
Questions
Answers
Answer accepted
Users
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us