### Basic Proxy Example with get() Handler Source: https://devdocs.io/javascript/global_objects/parsefloat Demonstrates a basic usage of the `Proxy` object with a `get()` handler to provide default values for non-existent properties. ```APIDOC ## Examples ### Basic example In this example, the number `37` gets returned as the default value when the property name is not in the object. It is using the `get()` handler. ```javascript const handler = { get(obj, prop) { return prop in obj ? obj[prop] : 37; }, }; const p = new Proxy({}, handler); p.a = 1; p.b = undefined; console.log(p.a, p.b); // 1, undefined console.log("c" in p, p.c); // false, 37 ``` ``` -------------------------------- ### Symfony Usage Examples Source: https://devdocs.io/javascript/global_objects/temporal/duration/round Examples demonstrating the usage of Symfony, a PHP web application framework, across different major versions. ```php Enable4.1.7Symfony 4.1 ``` ```php Enable4.0.3Symfony 4.0 ``` ```php Enable3.4.3Symfony 3.4 ``` ```php Enable3.3.15Symfony 3.3 ``` ```php Enable3.2.13Symfony 3.2 ``` ```php Enable3.1.8Symfony 3.1 ``` ```php Enable3.0.1Symfony 3.0 ``` ```php Enable2.8.28Symfony 2.8 ``` ```php Enable2.7.35Symfony 2.7 ``` -------------------------------- ### Yarn Usage Examples Source: https://devdocs.io/javascript/global_objects/temporal/duration/round Examples demonstrating the usage of Yarn, a package manager for JavaScript, across different versions. ```bash Enable4.5.1Yarn ``` ```bash Enable3.1.1Yarn 3 ``` ```bash Enable1.22.17Yarn Classic ``` -------------------------------- ### Socket.IO Usage Examples Source: https://devdocs.io/javascript/global_objects/temporal/duration/round Examples demonstrating the usage of Socket.IO, a library for real-time web applications, across different versions. ```javascript Enable4.5.2Socket.IO 4 ``` ```javascript Enable3.0.5Socket.IO 3 ``` ```javascript Enable2.4.0Socket.IO 2 ``` -------------------------------- ### Tcl/Tk Usage Examples Source: https://devdocs.io/javascript/global_objects/temporal/duration/round Examples demonstrating the usage of Tcl/Tk, a toolkit for creating graphical user interfaces, across different versions. ```tcl Enable9.0.2Tcl/Tk 9.0 ``` ```tcl Enable8.6.16Tcl/Tk 8.6 ``` -------------------------------- ### Werkzeug Usage Examples Source: https://devdocs.io/javascript/global_objects/temporal/duration/round Examples demonstrating the usage of Werkzeug, a WSGI utility library for Python, across different versions. ```python Enable3.1.1Werkzeug ``` ```python Enable3.0.xWerkzeug 3.0 ``` ```python Enable2.3.xWerkzeug 2.3 ``` ```python Enable2.2.xWerkzeug 2.2 ``` ```python Enable2.1.xWerkzeug 2.1 ``` ```python Enable2.0.xWerkzeug 2.0 ``` ```python Enable1.0.xWerkzeug 1.0 ``` ```python Enable0.16.xWerkzeug 0.16 ``` ```python Enable0.15.xWerkzeug 0.15 ``` -------------------------------- ### Sinon.JS Usage Examples Source: https://devdocs.io/javascript/global_objects/temporal/duration/round Examples demonstrating the usage of Sinon.JS, a JavaScript testing toolkit, across different versions. ```javascript Enable15.0.1Sinon.JS 15 ``` ```javascript Enable14.0.2Sinon.JS 14 ``` ```javascript Enable13.0.1Sinon.JS 13 ``` ```javascript Enable12.0.1Sinon.JS 12 ``` ```javascript Enable11.1.2Sinon.JS 11 ``` ```javascript Enable10.0.1Sinon.JS 10 ``` ```javascript Enable9.2.2Sinon.JS 9 ``` ```javascript Enable8.1.1Sinon.JS 8 ``` ```javascript Enable7.5.0Sinon.JS 7 ``` ```javascript Enable6.3.5Sinon.JS 6 ``` ```javascript Enable5.1.0Sinon.JS 5 ``` ```javascript Enable4.5.0Sinon.JS 4 ``` ```javascript Enable3.3.0Sinon.JS 3 ``` ```javascript Enable2.4.1Sinon.JS 2 ``` ```javascript Enable1.17.7Sinon.JS 1 ``` -------------------------------- ### Svelte Usage Examples Source: https://devdocs.io/javascript/global_objects/temporal/duration/round Examples demonstrating the usage of Svelte, a compiler for building user interfaces, across different major versions. ```javascript Enable5.38.10Svelte ``` ```javascript Enable4.2.1Svelte 4 ``` ```javascript Enable3.55.0Svelte 3 ``` -------------------------------- ### JavaScript Map Object Usage Example Source: https://devdocs.io/javascript/global_objects/isnan Demonstrates the creation and usage of a JavaScript `Map` object. It shows how to set key-value pairs using various data types as keys (string, object, function) and how to retrieve values using the `get()` method. It also logs the `size` property. ```javascript const myMap = new Map(); const keyString = "a string"; const keyObj = {}; const keyFunc = () => {}; // setting the values myMap.set(keyString, "value associated with 'a string'"); myMap.set(keyObj, "value associated with keyObj"); myMap.set(keyFunc, "value associated with keyFunc"); console.log(myMap.size); // 3 // getting the values console.log(myMap.get(keyString)); // "value associated with 'a string'" console.log(myMap.get(keyObj)); // "value associated with keyObj" console.log(myMap.get(keyFunc)); // "value associated with keyFunc" console.log(myMap.get("a string")); // "value associated with 'a string'", because keyString === 'a string' console.log(myMap.get({})); // undefined, because keyObj !== {} console.log(myMap.get(() => {})); // undefined, because keyFunc !== () => {} ``` -------------------------------- ### Yii Usage Examples Source: https://devdocs.io/javascript/global_objects/temporal/duration/round Examples demonstrating the usage of Yii, a high-performance PHP framework, across different major versions. ```php Enable2.0.12Yii 2.0 ``` ```php Enable1.1.19Yii 1.1 ``` -------------------------------- ### TensorFlow Usage Examples Source: https://devdocs.io/javascript/global_objects/temporal/duration/round Examples demonstrating the usage of TensorFlow, an open-source library for machine learning, across different versions. ```python Enable2.16.1TensorFlow ``` ```python Enable2.9.1TensorFlow 2.9 ``` ```python Enable2.4.0TensorFlow 2.4 ``` ```python Enable2.3.0TensorFlow 2.3 ``` ```python Enable1.15.0TensorFlow 1.15 ``` -------------------------------- ### Correct Map Usage in JavaScript Source: https://devdocs.io/javascript/global_objects/isnan Illustrates the correct method for storing and managing data in a JavaScript Map using the `set(key, value)` method. This example shows how to add entries, check for their existence with `has()`, retrieve values with `get()`, and remove entries with `delete()`. It also demonstrates how to correctly determine the number of entries using the `size` property. ```javascript const contacts = new Map(); contacts.set("Jessie", { phone: "213-555-1234", address: "123 N 1st Ave" }); contacts.has("Jessie"); // true contacts.get("Hilary"); // undefined contacts.set("Hilary", { phone: "617-555-4321", address: "321 S 2nd St" }); contacts.get("Jessie"); // {phone: "213-555-1234", address: "123 N 1st Ave"} contacts.delete("Raymond"); // false contacts.delete("Jessie"); // true console.log(contacts.size); // 1 ``` -------------------------------- ### TensorFlow C++ Usage Examples Source: https://devdocs.io/javascript/global_objects/temporal/duration/round Examples demonstrating the usage of TensorFlow C++, the C++ API for TensorFlow, across different versions. ```cpp Enable2.16.1TensorFlow C++ ``` ```cpp Enable2.9.1TensorFlow C++ 2.9 ``` ```cpp Enable2.4.0TensorFlow C++ 2.4 ``` ```cpp Enable2.3.0TensorFlow C++ 2.3 ``` ```cpp Enable1.15.0TensorFlow C++ 1.15 ``` -------------------------------- ### Vert.x Usage Examples Source: https://devdocs.io/javascript/global_objects/temporal/duration/round Examples demonstrating the usage of Vert.x, a toolkit for building reactive applications on the JVM, across different major versions. ```java Enable5.0.0Vert.x 5 ``` ```java Enable4.5.15Vert.x 4 ``` ```java Enable3.9.16Vert.x 3 ``` -------------------------------- ### JavaScript String.prototype.substr() Example Source: https://devdocs.io/javascript/global_objects/string/substr Demonstrates the usage of the substr() method to extract portions of a string. It shows how to get a substring with a specified start index and length, or from a start index to the end of the string. Note that this method is deprecated. ```javascript const str = "Mozilla"; console.log(str.substr(1, 2)); // Expected output: "oz" console.log(str.substr(2)); // Expected output: "zilla" ``` -------------------------------- ### Proxy get() Trap Example Source: https://devdocs.io/javascript/global_objects/parsefloat This example demonstrates the use of the 'get()' trap in a JavaScript Proxy. When a property is accessed that does not exist on the target object, it returns a default value of 37. This showcases how Proxies can intercept property access. ```javascript const handler = { get(obj, prop) { return prop in obj ? obj[prop] : 37; }, }; const p = new Proxy({}, handler); p.a = 1; p.b = undefined; console.log(p.a, p.b); // 1, undefined console.log("c" in p, p.c); // false, 37 ``` -------------------------------- ### Spring Boot Integration Examples Source: https://devdocs.io/javascript/global_objects/temporal/duration/round Indicates availability of documentation for Spring Boot integration. ```java Enable3.1.3Spring Boot ``` -------------------------------- ### Varnish Usage Examples Source: https://devdocs.io/javascript/global_objects/temporal/duration/round Indicates availability of documentation for Varnish Cache, a web application accelerator. ```c Enable7.4Varnish ``` -------------------------------- ### Vagrant Usage Examples Source: https://devdocs.io/javascript/global_objects/temporal/duration/round Indicates availability of documentation for Vagrant, a tool for building and managing virtual machine environments. ```ruby Enable2.2.0Vagrant ``` -------------------------------- ### JavaScript: Variable names starting with numeric literals Source: https://devdocs.io/javascript/errors/hash_outside_class In JavaScript, variable names cannot start with numbers. This snippet shows an example of a failing variable declaration and its correct alternative, emphasizing the need to rename variables that begin with a digit. ```javascript const 1life = "foo"; // SyntaxError: identifier starts immediately after numeric literal const foo = 1life; // SyntaxError: identifier starts immediately after numeric literal ``` ```javascript const life1 = "foo"; const foo = life1; ``` -------------------------------- ### JavaScript Temporal.PlainDateTime.prototype.year Example Source: https://devdocs.io/javascript/global_objects/temporal/plaindatetime/tozoneddatetime This example demonstrates how to get the year from a Temporal.PlainDateTime object. The 'year' property returns an integer representing the year. It cannot be directly set; use the 'with()' method for modifications. ```javascript const dt = Temporal.PlainDateTime.from("2021-07-01"); // ISO 8601 calendar console.log(dt.year); // 2021 ``` -------------------------------- ### Temporal.Instant Constructor and Static Methods Source: https://devdocs.io/javascript/global_objects/syntaxerror/syntaxerror This section covers the creation of Temporal.Instant objects using the constructor and static factory methods, along with comparison utilities. ```APIDOC ## Temporal.Instant Constructor and Static Methods ### Description This section covers the creation of `Temporal.Instant` objects using the constructor and static factory methods, along with comparison utilities. ### Methods #### `Temporal.Instant()` Creates a new `Temporal.Instant` object by directly supplying the underlying data. #### `Temporal.Instant.compare(instant1, instant2)` Returns a number (-1, 0, or 1) indicating whether the first instant comes before, is the same as, or comes after the second instant. Equivalent to comparing the `epochNanoseconds` of the two instants. **Parameters:** - `instant1` (Temporal.Instant) - The first instant to compare. - `instant2` (Temporal.Instant) - The second instant to compare. #### `Temporal.Instant.from(value)` Creates a new `Temporal.Instant` object from another `Temporal.Instant` object, or an RFC 9557 string. **Parameters:** - `value` (Temporal.Instant or string) - The value to convert to an `Instant`. #### `Temporal.Instant.fromEpochMilliseconds(milliseconds)` Creates a new `Temporal.Instant` object from the number of milliseconds since the Unix epoch. **Parameters:** - `milliseconds` (number) - The number of milliseconds since the Unix epoch. #### `Temporal.Instant.fromEpochNanoseconds(nanoseconds)` Creates a new `Temporal.Instant` object from the number of nanoseconds since the Unix epoch. **Parameters:** - `nanoseconds` (BigInt) - The number of nanoseconds since the Unix epoch. ### Request Example ```json { "example": "// Creating an instant from a string\nconst instant = Temporal.Instant.from('2023-10-27T10:00:00Z');\n\n// Comparing two instants\nconst result = Temporal.Instant.compare(instant1, instant2);" } ``` ### Response #### Success Response (200) - **number** (number) - Result of comparison for `Temporal.Instant.compare()`. - **Temporal.Instant** (Temporal.Instant) - Newly created `Instant` object for `from`, `fromEpochMilliseconds`, and `fromEpochNanoseconds`. #### Response Example ```json { "example": "// For Temporal.Instant.compare(): -1, 0, or 1\n// For Temporal.Instant.from(): Temporal.Instant { ... }" } ``` ``` -------------------------------- ### JavaScript Array slice() - Positive Start and Negative End Index Source: https://devdocs.io/javascript/global_objects/array/push This example shows how to use a positive start index and a negative end index with slice(). The method extracts elements from the start index up to, but not including, the element at the negative end index. The original array is not modified. ```javascript const fruits = ["Apple", "Banana", "Orange", "Mango", "Pineapple"]; // Using positive start index and negative end index const sliceExample = fruits.slice(1, -1); console.log(sliceExample); // ['Banana', 'Orange', 'Mango'] ``` -------------------------------- ### Temporal.Duration.prototype.seconds Example Source: https://devdocs.io/javascript/global_objects/temporal/duration/seconds This example demonstrates how to use the `seconds` accessor property of Temporal.Duration instances. It shows how to get the number of seconds from different duration objects and how balancing a duration can affect the `seconds` value. ```javascript const d1 = Temporal.Duration.from({ minutes: 1, seconds: 30 }); const d2 = Temporal.Duration.from({ minutes: -1, seconds: -30 }); const d3 = Temporal.Duration.from({ minutes: 1 }); const d4 = Temporal.Duration.from({ seconds: 60 }); console.log(d1.seconds); // 30 console.log(d2.seconds); // -30 console.log(d3.seconds); // 0 console.log(d4.seconds); // 60 // Balance d4 const d4Balanced = d4.round({ largestUnit: "minutes" }); console.log(d4Balanced.seconds); // 0 console.log(d4Balanced.minutes); // 1 ``` -------------------------------- ### JavaScript handler.defineProperty() Example Source: https://devdocs.io/javascript/global_objects/proxy/proxy/defineproperty This example demonstrates the usage of the handler.defineProperty() method within a Proxy object. It includes an invariant function to validate property names, preventing the definition of private properties starting with an underscore. The example shows how attempting to define a private property throws an error. ```javascript const handler = { defineProperty(target, key, descriptor) { invariant(key, "define"); return true; }, }; function invariant(key, action) { if (key[0] === "_") { throw new Error(`Invalid attempt to ${action} private "${key}" property`); } } const monster = {}; const proxy = new Proxy(monster, handler); console.log((proxy._secret = "easily scared")); // Expected output: Error: Invalid attempt to define private "_secret" property ``` -------------------------------- ### SQLite Integration Examples Source: https://devdocs.io/javascript/global_objects/temporal/duration/round Indicates availability of documentation for SQLite integration. ```sql Enable3.50.0SQLite ``` -------------------------------- ### JavaScript Date.now() Example: Measuring Time Source: https://devdocs.io/javascript/global_objects/date/now This example demonstrates how to use Date.now() to measure the time elapsed for a setTimeout function. It captures the start time, waits for 2 seconds, and then calculates and logs the difference in seconds. ```javascript const start = Date.now(); console.log("starting timer..."); // Expected output: "starting timer..." setTimeout(() => { const ms = Date.now() - start; console.log(`seconds elapsed = ${Math.floor(ms / 1000)}`); // Expected output: "seconds elapsed = 2" }, 2000); ``` -------------------------------- ### Vuex Usage Examples Source: https://devdocs.io/javascript/global_objects/temporal/duration/round Examples demonstrating the usage of Vuex, the official state management library for Vue.js, across different major versions. ```javascript Enable4.0.2Vuex 4 ``` ```javascript Enable3.6.2Vuex 3 ``` -------------------------------- ### Temporal.PlainMonthDay.prototype.toJSON() Example Source: https://devdocs.io/javascript/global_objects/temporal/plainmonthday/tojson Demonstrates how to use the toJSON() method to get a string representation of a Temporal.PlainMonthDay object and deserialize it back. ```javascript const md = Temporal.PlainMonthDay.from({ month: 8, day: 1 }); const mdStr = md.toJSON(); // '08-01' const md2 = Temporal.PlainMonthDay.from(mdStr); ``` ```javascript const md = Temporal.PlainMonthDay.from({ month: 8, day: 1 }); const jsonStr = JSON.stringify({ birthday: md }); // '{"birthday":"08-01"}' const obj = JSON.parse(jsonStr, (key, value) => { if (key === "birthday") { return Temporal.PlainMonthDay.from(value); } return value; }); ``` -------------------------------- ### JavaScript Date.now() Example: Measuring Process Time Source: https://devdocs.io/javascript/global_objects/date/now This example illustrates measuring the execution time of a function using Date.now(). It records the start timestamp before calling a placeholder function 'doSomeLongRunningProcess()' and then calculates the elapsed time in milliseconds after its completion. ```javascript const start = Date.now(); doSomeLongRunningProcess(); console.log(`Time elapsed: ${Date.now() - start} ms`); ``` -------------------------------- ### Wagtail Usage Examples Source: https://devdocs.io/javascript/global_objects/temporal/duration/round Examples demonstrating the usage of Wagtail, a content management system built on Django, across different major versions. ```python Enable4.1.1Wagtail ``` ```python Enable3.0.3Wagtail 3 ``` ```python Enable2.16.3Wagtail 2 ``` -------------------------------- ### Temporal.PlainDate.prototype.toString() Example Source: https://devdocs.io/javascript/global_objects/temporal/plaindate/toplaindatetime Demonstrates the basic usage of the toString() method on a Temporal.PlainDate instance to get a string representation of the date. ```javascript const date = Temporal.PlainDate.from("2021-08-01"); console.log(date.toString()); // '2021-08-01' ``` -------------------------------- ### Get Next Chinese New Year Occurrence - JavaScript Example Source: https://devdocs.io/javascript/global_objects/temporal/plainmonthday This example demonstrates how to calculate the next occurrence of Chinese New Year using Temporal.PlainMonthDay. It involves creating a PlainMonthDay object for Chinese New Year, determining the current year in the Chinese calendar, and calculating the next New Year date. The example utilizes Temporal.PlainDate.compare and the add method for date manipulation. ```javascript const chineseNewYear = Temporal.PlainMonthDay.from({ monthCode: "M01", day: 1, calendar: "chinese", }); const currentYear = Temporal.Now.plainDateISO().withCalendar("chinese").year; let nextCNY = chineseNewYear.toPlainDate({ year: currentYear }); if (Temporal.PlainDate.compare(nextCNY, Temporal.Now.plainDateISO()) <= 0) { nextCNY = nextCNY.add({ years: 1 }); } console.log( `The next Chinese New Year is on ${nextCNY.withCalendar("iso8601").toLocaleString()}`, ); ``` -------------------------------- ### Zsh Usage Examples Source: https://devdocs.io/javascript/global_objects/temporal/duration/round Indicates availability of documentation for Zsh, a powerful shell with many features. ```bash Enable5.9.0Zsh ``` -------------------------------- ### Add Durations using Temporal.Duration in JavaScript Source: https://devdocs.io/javascript/global_objects/regexp/unicodesets Demonstrates adding Temporal.Duration instances in JavaScript. It highlights that direct addition of calendar durations is not supported and requires date arithmetic relative to a starting point. The example shows successful addition using a starting PlainDateTime object. ```javascript const d1 = Temporal.Duration.from({ days: 1 }); const d2 = Temporal.Duration.from({ months: 1 }); d1.add(d2); // RangeError: for calendar duration arithmetic, use date arithmetic relative to a starting point const start = Temporal.PlainDateTime.from("2022-01-01T00:00"); // ISO 8601 calendar const result = start.add(d1).add(d2).since(start); console.log(result.toString()); // "P32D" ``` -------------------------------- ### Using slice() to create a new string Source: https://devdocs.io/javascript/global_objects/string/slice This example demonstrates how to use the slice() method to create new strings by extracting portions of an existing string. It shows slicing from a start index to an end index, from a start index to the end, and handling out-of-bounds indexes. ```javascript const str1 = "The morning is upon us."; // The length of str1 is 23. const str2 = str1.slice(1, 8); const str3 = str1.slice(4, -2); const str4 = str1.slice(12); const str5 = str1.slice(30); console.log(str2); // he morn console.log(str3); // morning is upon u console.log(str4); // is upon us. console.log(str5); // "" ``` -------------------------------- ### Temporal.ZonedDateTime.prototype.minute Usage Example Source: https://devdocs.io/javascript/global_objects/temporal/zoneddatetime/millisecond Demonstrates how to get the minute component from a Temporal.ZonedDateTime instance. This property is read-only and reflects the minute of the zoned date-time. ```javascript const dt = Temporal.ZonedDateTime.from( "2021-07-01T12:34:56.123456789-04:00[America/New_York]", ); console.log(dt.minute); // 34 ``` -------------------------------- ### JavaScript String substr() Method Examples Source: https://devdocs.io/javascript/global_objects/string/symbol Demonstrates various use cases of the substr() method in JavaScript, including extracting characters from the start, with zero length, from the end, with negative length, and when start index is out of bounds. It highlights how substr() handles different parameter combinations. ```javascript const string = "Mozilla"; console.log(string.substr(0, 1)); // 'M' console.log(string.substr(1, 0)); // '' console.log(string.substr(-1, 1)); // 'a' console.log(string.substr(1, -1)); // '' console.log(string.substr(-3)); // 'lla' console.log(string.substr(1)); // 'ozilla' console.log(string.substr(-20, 2)); // 'Mo' console.log(string.substr(20, 2)); // '' ``` -------------------------------- ### Vite Usage Examples Source: https://devdocs.io/javascript/global_objects/temporal/duration/round Examples demonstrating the usage of Vite, a next generation frontend tooling that significantly improves the frontend development experience, across different major versions. ```javascript Enable7.1.2Vite ``` ```javascript Enable6.3.5Vite 6 ``` ```javascript Enable5.4.11Vite 5 ``` ```javascript Enable4.5.5Vite 4 ``` ```javascript Enable3.2.11Vite 3 ``` -------------------------------- ### WordPress Usage Examples Source: https://devdocs.io/javascript/global_objects/temporal/duration/round Indicates availability of documentation for WordPress, a popular content management system. ```php Enable6.7WordPress ``` -------------------------------- ### Resolving Path for Worker() Constructor in JavaScript Source: https://devdocs.io/javascript/global_objects/weakset/weakset Provides an example of using import.meta.resolve() to get the URL for a worker script, which is then used to instantiate a new Worker. This showcases a practical application of the method for APIs requiring script paths. The example includes both the main script and the worker script. ```javascript // main.js const workerPath = import.meta.resolve("./worker.js"); const worker = new Worker(workerPath, { type: "module" }); worker.addEventListener("message", console.log); ``` ```javascript // worker.js self.postMessage("hello!"); ``` -------------------------------- ### Temporal.PlainYearMonth.prototype.daysInYear Example - JavaScript Source: https://devdocs.io/javascript/global_objects/temporal/plainyearmonth/equals This example demonstrates how to use the `daysInYear` accessor property of `Temporal.PlainYearMonth` to get the number of days in a given year. It creates a `PlainYearMonth` instance and logs the `daysInYear` property to the console. This feature's availability is dependent on the browser's Temporal API support. ```javascript const ym = Temporal.PlainYearMonth.from("2021-07"); console.log(ym.daysInYear); // 365 ``` -------------------------------- ### JavaScript Object Initializer Example Source: https://devdocs.io/javascript/operators/object_initializer Demonstrates the creation and usage of object initializers in JavaScript. It shows direct initialization, initialization using variables, and shorthand property initialization. ```javascript const object1 = { a: "foo", b: 42, c: {} }; console.log(object1.a); // Expected output: "foo" const a = "foo"; const b = 42; const c = {}; const object2 = { a: a, b: b, c: c }; console.log(object2.b); // Expected output: 42 const object3 = { a, b, c }; console.log(object3.a); // Expected output: "foo" ``` -------------------------------- ### JavaScript Intl.NumberFormat.prototype.formatRangeToParts() Example Source: https://devdocs.io/javascript/global_objects/intl/numberformat/formatrangetoparts This example demonstrates the usage of the formatRangeToParts() method in JavaScript. It shows how to create an Intl.NumberFormat object and use formatRangeToParts() to get locale-specific tokens for a number range. The output is an array of objects, each with 'type', 'value', and 'source' properties, which can be used to construct custom formatted strings. ```javascript const formatter = new Intl.NumberFormat('en-US', { notation: 'standard', unitDisplay: 'long' }); console.log(formatter.formatRangeToParts(1000, 2000)); // Expected output: an array of objects representing the formatted range parts. console.log(formatter.formatRangeToParts(50, 50)); // Expected output: an array of objects representing the formatted range parts, potentially with an 'approximatelySign'. ``` -------------------------------- ### JavaScript TypedArray.prototype.entries() Example Source: https://devdocs.io/javascript/global_objects/typedarray/entries Demonstrates the usage of the entries() method on a TypedArray to get an iterator for key-value pairs. It shows how to retrieve the next value from the iterator. ```javascript const uint8 = new Uint8Array([10, 20, 30, 40, 50]); const eArr = uint8.entries(); eArr.next(); eArr.next(); console.log(eArr.next().value); // Expected output: Array [2, 30] ``` -------------------------------- ### Vulkan Usage Examples Source: https://devdocs.io/javascript/global_objects/temporal/duration/round Indicates availability of documentation for Vulkan, a low-overhead, cross-platform 3D graphics and computing API. ```c Enable1.0.59Vulkan ``` -------------------------------- ### JavaScript setUTCMinutes() Example Source: https://devdocs.io/javascript/global_objects/date/setutcmilliseconds Demonstrates how to use the setUTCMinutes() method to get and set the minutes of a Date object in UTC. It shows the output before and after the modification. ```javascript const date = new Date("December 31, 1975, 23:15:30 GMT+11:00"); console.log(date.getUTCMinutes()); // Expected output: 15 date.setUTCMinutes(25); console.log(date.getUTCMinutes()); // Expected output: 25 ``` -------------------------------- ### Webpack Usage Examples Source: https://devdocs.io/javascript/global_objects/temporal/duration/round Examples demonstrating the usage of Webpack, a static module bundler for JavaScript applications, across different major versions. ```javascript Enable5.97.1webpack 5 ``` ```javascript Enable4.44.2webpack 4 ``` ```javascript Enable1.15.0webpack 1 ``` -------------------------------- ### JavaScript Date getUTCDate() Usage Source: https://devdocs.io/javascript/global_objects/date/getutcdate A simple example showing how to get the day of the month for the current date using the getUTCDate() method and store it in a variable. ```javascript const today = new Date(); const dayOfMonth = today.getUTCDate(); ``` -------------------------------- ### Vue Usage Examples Source: https://devdocs.io/javascript/global_objects/temporal/duration/round Examples demonstrating the usage of Vue.js, a progressive JavaScript framework for building user interfaces, across different major versions. ```javascript Enable3.5.18Vue 3 ``` ```javascript Enable2.7.14Vue 2 ``` ```javascript Enable1.0.28Vue 1 ``` -------------------------------- ### JavaScript Date getTime() Example Source: https://devdocs.io/javascript/global_objects/date/getseconds Demonstrates how to use the getTime() method to get the number of milliseconds since the epoch for a given date. This is useful for timestamp manipulation and comparisons. ```javascript const moonLanding = new Date("July 20, 69 20:17:40 GMT+00:00"); // Milliseconds since Jan 1, 1970, 00:00:00.000 GMT console.log(moonLanding.getTime()); // Expected output: -14182940000 ``` -------------------------------- ### Vitest Usage Examples Source: https://devdocs.io/javascript/global_objects/temporal/duration/round Examples demonstrating the usage of Vitest, a unit testing framework optimized for Vite, across different major versions. ```javascript Enable3.0.8Vitest ``` ```javascript Enable2.1.9Vitest 2 ``` -------------------------------- ### Twig Usage Examples Source: https://devdocs.io/javascript/global_objects/temporal/duration/round Examples demonstrating the usage of Twig, a flexible, fast, and secure template engine for PHP, across different major versions. ```twig Enable3.1.1Twig 3 ``` ```twig Enable2.14.1Twig 2 ``` ```twig Enable1.44.1Twig 1 ``` -------------------------------- ### JavaScript Date.prototype.getDay() Example Source: https://devdocs.io/javascript/global_objects/date/getday Demonstrates how to use the `getDay()` method to get the day of the week from a Date object. The method returns an integer from 0 (Sunday) to 6 (Saturday). ```javascript const birthday = new Date("August 19, 1975 23:15:30"); const day1 = birthday.getDay(); // Sunday - Saturday : 0 - 6 console.log(day1); // Expected output: 2 ``` ```javascript const xmas95 = new Date("1995-12-25T23:15:30"); const weekday = xmas95.getDay(); console.log(weekday); // 1 ``` -------------------------------- ### Trio Usage Examples Source: https://devdocs.io/javascript/global_objects/temporal/duration/round Indicates availability of documentation for Trio, a Python library for async concurrency. ```python Enable0.29.0Trio ``` -------------------------------- ### JavaScript TypedArray.prototype.copyWithin() Example Source: https://devdocs.io/javascript/global_objects/typedarray/bytelength Demonstrates the usage of the copyWithin() method on a Uint8Array instance. This method copies elements from a specified start and end index to a target index within the same array. ```javascript const uint8 = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); // Insert position, start position, end position uint8.copyWithin(3, 1, 3); console.log(uint8); // Expected output: Uint8Array [1, 2, 3, 2, 3, 6, 7, 8] ``` ```javascript const buffer = new ArrayBuffer(8); const uint8 = new Uint8Array(buffer); uint8.set([1, 2, 3]); console.log(uint8); // Uint8Array [ 1, 2, 3, 0, 0, 0, 0, 0 ] uint8.copyWithin(3, 0, 3); console.log(uint8); // Uint8Array [ 1, 2, 3, 1, 2, 3, 0, 0 ] ``` -------------------------------- ### JavaScript Reflect.get() Examples with Proxies Source: https://devdocs.io/javascript/global_objects/reflect/get Shows advanced usage of Reflect.get() with JavaScript Proxies, including scenarios with custom get handlers and the 'receiver' parameter to control 'this' context. ```javascript // Object const obj1 = { x: 1, y: 2 }; Reflect.get(obj1, "x"); // 1 // Array Reflect.get(["zero", "one"], 1); // "one" // Proxy with a get handler const obj2 = new Proxy( { p: 1 }, { get(t, k, r) { return `${k}bar`; }, }, ); Reflect.get(obj2, "foo"); // "foobar" // Proxy with get handler and receiver const obj3 = new Proxy( { p: 1, foo: 2 }, { get(t, prop, receiver) { return `${receiver[prop]}bar`; }, }, ); Reflect.get(obj3, "foo", { foo: 3 }); // "3bar" ``` -------------------------------- ### JavaScript Array Literal Notation Example Source: https://devdocs.io/javascript/global_objects/array/at Illustrates creating an array using JavaScript's literal notation. This method is concise for initializing arrays with predefined elements and is widely compatible. ```javascript const fruits = ["Apple", "Banana"]; console.log(fruits.length); // 2 console.log(fruits[0]); // "Apple" ``` -------------------------------- ### Temporal.PlainDate.prototype.day - JavaScript Example Source: https://devdocs.io/javascript/global_objects/temporal/plaindate/compare Demonstrates how to use the `day` accessor property of `Temporal.PlainDate` to get the day of the month. It shows how to create a date using the ISO 8601 calendar and a custom calendar (Chinese). ```javascript const date = Temporal.PlainDate.from("2021-07-01"); // ISO 8601 calendar console.log(date.day); // 1 const date2 = Temporal.PlainDate.from("2021-07-01[u-ca=chinese]"); console.log(date2.day); // 22; it is May 22 in the Chinese calendar ``` -------------------------------- ### VueUse Usage Examples Source: https://devdocs.io/javascript/global_objects/temporal/duration/round Indicates availability of documentation for VueUse, a collection of essential Vue Composition API utilities. ```javascript Enable13.6.0VueUse ``` -------------------------------- ### JavaScript Intl.DisplayNames.prototype.of() Example Source: https://devdocs.io/javascript/global_objects/intl/datetimeformat/supportedlocalesof Demonstrates the usage of the Intl.DisplayNames.prototype.of() method to get region names in English and Traditional Chinese. This method takes a code and returns a locale-specific string based on the instantiation options. ```javascript const regionNamesInEnglish = new Intl.DisplayNames(["en"], { type: "region" }); const regionNamesInTraditionalChinese = new Intl.DisplayNames(["zh-Hant"], { type: "region", }); console.log(regionNamesInEnglish.of("US")); // Expected output: "United States" console.log(regionNamesInTraditionalChinese.of("US")); // Expected output: "美國" ``` -------------------------------- ### Zig Usage Examples Source: https://devdocs.io/javascript/global_objects/temporal/duration/round Indicates availability of documentation for Zig, a general-purpose programming language. ```zig Enable0.15.2Zig ``` -------------------------------- ### JavaScript: Temporal.ZonedDateTime startOfDay() Example Source: https://devdocs.io/javascript/global_objects/temporal/zoneddatetime/round Demonstrates the usage of the startOfDay() method on Temporal.ZonedDateTime objects. It shows how the method returns the start of the day in the specified time zone, accounting for potential DST transitions where midnight might not exist. ```javascript // In the US, DST transitions happen at 2am, so the midnight exists const dt = Temporal.ZonedDateTime.from( "2024-03-10T12:00:00-04:00[America/New_York]", ); console.log(dt.startOfDay().toString()); // "2024-03-10T00:00:00-05:00[America/New_York]" // In Brazil, DST transitions happened at midnight, so the midnight didn't exist const dt2 = Temporal.ZonedDateTime.from( "2015-10-18T12:00-02:00[America/Sao_Paulo]", ); console.log(dt2.startOfDay().toString()); // "2015-10-18T01:00:00-02:00[America/Sao_Paulo]" ``` -------------------------------- ### Get dayOfYear in JavaScript Source: https://devdocs.io/javascript/global_objects/temporal/plaindate/dayofyear This snippet demonstrates how to retrieve the day of the year from a `Temporal.PlainDate` object. It shows examples for the Gregorian calendar and a Chinese calendar, and accounts for leap years. The `dayOfYear` property is read-only. ```javascript const date = Temporal.PlainDate.from("2021-07-01"); console.log(date.dayOfYear); // 182 const date2 = Temporal.PlainDate.from("2021-07-01[u-ca=chinese]"); console.log(date2.dayOfYear); // 140 const date3 = Temporal.PlainDate.from("2020-07-01"); console.log(date3.dayOfYear); // 183; 2020 is a leap year ``` -------------------------------- ### JavaScript Symbol() Syntax and Parameters Source: https://devdocs.io/javascript/global_objects/symbol/search Illustrates the syntax for the Symbol() constructor, including the optional description parameter. It highlights that symbols are created directly and not with the 'new' keyword. ```javascript Symbol() Symbol(description) ``` -------------------------------- ### Temporal.PlainDate.prototype.calendarId - JavaScript Example Source: https://devdocs.io/javascript/global_objects/temporal/plaindate/calendarid Demonstrates how to use the `calendarId` property to get the calendar of a Temporal.PlainDate instance and how to use `withCalendar()` to create a new instance with a different calendar. Note that the set accessor for `calendarId` is undefined. ```javascript const date = Temporal.PlainDate.from("2021-07-01"); console.log(date.calendarId); // "iso8601"; default const date2 = Temporal.PlainDate.from("2021-07-01[u-ca=chinese]"); console.log(date2.calendarId); // "chinese" const date3 = date2.withCalendar("hebrew"); console.log(date3.calendarId); // "hebrew" ``` -------------------------------- ### Tailwind CSS Usage Examples Source: https://devdocs.io/javascript/global_objects/temporal/duration/round Examples demonstrating the usage of Tailwind CSS, a utility-first CSS framework, across different major versions. ```css Enable4.1.11Tailwind CSS ``` ```css Enable3.4.17Tailwind CSS 3 ```