From d9fb76816b1d4291bf109707bb2d9f77dbb84bd0 Mon Sep 17 00:00:00 2001 From: roeib Date: Wed, 14 Apr 2021 07:51:32 +0300 Subject: [PATCH 1/9] Native text to speech JS --- README.md | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fb62f64..f08592d 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ |39 | [Numeric separators allow us to improve our code readability](#Numeric-separators-allow-us-to-improve-our-code-readability)| |40 | [pay attention when using every](#pay-attention-when-using-every)| |41 | [How to convert an array of key-value tuples into an object](#How-to-convert-an-array-of-key-value-tuples-into-an-object)| - +|42 | [Native text to speech JS](#Native-text-to-speech-JS)| @@ -903,4 +903,25 @@ const obj = Object.fromEntries(JSarr); //} ``` +**[⬆ Back to Top](#table-of-contents)** +### Native text to speech JS + + +```javascript + +const startSpeaking=()=>{ + let msg = document.getElementById("text-to-speech").value; + let speech = new SpeechSynthesisUtterance(); + + speech.lang = "en-US"; + speech.text = msg; + speech.volume = 1; + speech.rate = 1; + speech.pitch = 1; + + window.speechSynthesis.speak(speech); +} + + +``` From 795fb29021bee1c79cf2b5572380c2d457dabef2 Mon Sep 17 00:00:00 2001 From: roeib Date: Tue, 5 Oct 2021 12:09:37 +0300 Subject: [PATCH 2/9] toFixed --- README.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f08592d..9d8ef32 100644 --- a/README.md +++ b/README.md @@ -46,8 +46,7 @@ |40 | [pay attention when using every](#pay-attention-when-using-every)| |41 | [How to convert an array of key-value tuples into an object](#How-to-convert-an-array-of-key-value-tuples-into-an-object)| |42 | [Native text to speech JS](#Native-text-to-speech-JS)| - - +|42 | [Native text to speech JS](#Native-text-to-speech-JS)| @@ -924,4 +923,19 @@ const startSpeaking=()=>{ } +``` + +**[⬆ Back to Top](#table-of-contents)** +### toFixed() + +Warning: Floating point numbers cannot represent all decimals precisely in binary. This can lead to unexpected results, such as 0.1 + 0.2 === 0.3 returning false . + +```javascript + +123.678.toFixed() // Returns '124' +123.678.toFixed(1) // Returns '123.7': Note rounding + +2.35.toFixed(1) // Returns '2.4'. Note it rounds up +2.65.toFixed(1) // Returns '2.6'. Note it rounds down -why??? see the warning above + ``` From d0d13903cfbc7ccf504a0458a1b0438c510db287 Mon Sep 17 00:00:00 2001 From: roeib Date: Tue, 5 Oct 2021 12:10:21 +0300 Subject: [PATCH 3/9] toFixed-table-of-content --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9d8ef32..f419b8a 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ |40 | [pay attention when using every](#pay-attention-when-using-every)| |41 | [How to convert an array of key-value tuples into an object](#How-to-convert-an-array-of-key-value-tuples-into-an-object)| |42 | [Native text to speech JS](#Native-text-to-speech-JS)| -|42 | [Native text to speech JS](#Native-text-to-speech-JS)| +|42 | [toFixed](#toFixed)| @@ -926,7 +926,7 @@ const startSpeaking=()=>{ ``` **[⬆ Back to Top](#table-of-contents)** -### toFixed() +### toFixed Warning: Floating point numbers cannot represent all decimals precisely in binary. This can lead to unexpected results, such as 0.1 + 0.2 === 0.3 returning false . From 0f3bfaada86bf5de913ca31a71392a095251dcf3 Mon Sep 17 00:00:00 2001 From: roeib Date: Tue, 5 Oct 2021 12:10:45 +0300 Subject: [PATCH 4/9] line number --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f419b8a..bdfb40b 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ |40 | [pay attention when using every](#pay-attention-when-using-every)| |41 | [How to convert an array of key-value tuples into an object](#How-to-convert-an-array-of-key-value-tuples-into-an-object)| |42 | [Native text to speech JS](#Native-text-to-speech-JS)| -|42 | [toFixed](#toFixed)| +|43 | [toFixed](#toFixed)| From 582356cbe3d5a14e7c33d71f4743ff7bd45fdcd9 Mon Sep 17 00:00:00 2001 From: roeib Date: Tue, 15 Mar 2022 09:46:20 +0200 Subject: [PATCH 5/9] randomUUID --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index bdfb40b..de6bad4 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,10 @@ |41 | [How to convert an array of key-value tuples into an object](#How-to-convert-an-array-of-key-value-tuples-into-an-object)| |42 | [Native text to speech JS](#Native-text-to-speech-JS)| |43 | [toFixed](#toFixed)| +|44 | [generate randomUUID](#generate-random-uuid)| + + + @@ -939,3 +943,18 @@ Warning: Floating point numbers cannot represent all decimals precisely in binar 2.65.toFixed(1) // Returns '2.6'. Note it rounds down -why??? see the warning above ``` + + +**[⬆ Back to Top](#table-of-contents)** +### generate random uuid + +The randomUUID() method of the Crypto interface is used to generate a v4 UUID using a cryptographically secure random number generator. + +```javascript + +crypto.randomUUID() // print in console '460ff1e6-2106-4848-833d-5c5b3bfdc943' + +crypto.randomUUID() // print in console '9a91c014-d1b1-453a-8091-ef8b9b48b14a' + + +``` From b34f9d143865d82b9fba9a94bcc3f3b81b568cc2 Mon Sep 17 00:00:00 2001 From: roeib Date: Wed, 3 Aug 2022 11:25:15 +0300 Subject: [PATCH 6/9] structuredClone --- README.md | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index de6bad4..cf3f505 100644 --- a/README.md +++ b/README.md @@ -48,9 +48,7 @@ |42 | [Native text to speech JS](#Native-text-to-speech-JS)| |43 | [toFixed](#toFixed)| |44 | [generate randomUUID](#generate-random-uuid)| - - - +|45 | [structuredClone](#structuredClone)| @@ -957,4 +955,30 @@ crypto.randomUUID() // print in console '460ff1e6-2106-4848-833d-5c5b3bfdc943' crypto.randomUUID() // print in console '9a91c014-d1b1-453a-8091-ef8b9b48b14a' +``` + + +**[⬆ Back to Top](#table-of-contents)** +### structuredClone + +If you want to deep clone a value in Node.js, you no longer need to use a library or the JSON.parse(JSON.stringify(value)) hack. You can use the new global function structuredClone() + +```javascript + +const user = { + name: "JS Snippets", + address: { street: "Original Road", city: "Placeshire" }, +}; + +const clonedUser = structuredClone(user); + +clonedUser.address.street = "New Road"; + +console.log("user.address.street:", user.address.street); +// > Original Road + +console.log("clonedUser.address.street:", clonedUser.address.street); +// > New Road + + ``` From b2d0d5e7cef104535d7d087dd4a0ba2c1105a5b5 Mon Sep 17 00:00:00 2001 From: roeib Date: Mon, 30 Jan 2023 16:23:25 +0200 Subject: [PATCH 7/9] get device orientation get device orientation --- README.md | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cf3f505..3046c8b 100644 --- a/README.md +++ b/README.md @@ -49,9 +49,7 @@ |43 | [toFixed](#toFixed)| |44 | [generate randomUUID](#generate-random-uuid)| |45 | [structuredClone](#structuredClone)| - - - +|46 | [get device orientation](#get-device-orientation)| **[⬆ Back to Top](#table-of-contents)** @@ -981,4 +979,18 @@ console.log("clonedUser.address.street:", clonedUser.address.street); // > New Road +``` + +**[⬆ Back to Top](#table-of-contents)** +### get device orientation + +Browsers expose a global variable named screen, which we’ll use to access the information we need. + +```javascript + +function getOrientation() { + const isPortrait = screen.orientation.type.startswith('portrait') + return isPortrait ? 'portrait' : 'landscape' +} + ``` From 8f85e7133d4c0c7563a6afe2b5541a79c2bc92c2 Mon Sep 17 00:00:00 2001 From: roeib Date: Wed, 8 Feb 2023 11:40:56 +0200 Subject: [PATCH 8/9] CONST vs LET vs VAR --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3046c8b..da616aa 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ |44 | [generate randomUUID](#generate-random-uuid)| |45 | [structuredClone](#structuredClone)| |46 | [get device orientation](#get-device-orientation)| - +|47 | [CONST vs LET vs VAR](#const-let-var)| **[⬆ Back to Top](#table-of-contents)** ### How to generate a random number in a given range @@ -994,3 +994,14 @@ function getOrientation() { } ``` + +**[⬆ Back to Top](#table-of-contents)** +### CONST vs LET vs VAR + +| | const | Let | Var | +|------------------------|-------|-----|-----| +| Can be Reaasigned? | X | :white_check_mark: | V | +| Cab be Redeclared? | X | X | V | +| Block Scope | V | V | X | +| Function Scope | V | V | V | +| Stored in Global Scope | X | X | V | From 23fe606caaa26c9ffde116274b56afdd9455bc72 Mon Sep 17 00:00:00 2001 From: roeib Date: Wed, 8 Feb 2023 11:43:49 +0200 Subject: [PATCH 9/9] Update README.md --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index da616aa..dcd01f3 100644 --- a/README.md +++ b/README.md @@ -1000,8 +1000,8 @@ function getOrientation() { | | const | Let | Var | |------------------------|-------|-----|-----| -| Can be Reaasigned? | X | :white_check_mark: | V | -| Cab be Redeclared? | X | X | V | -| Block Scope | V | V | X | -| Function Scope | V | V | V | -| Stored in Global Scope | X | X | V | +| Can be Reaasigned? | :x: | :white_check_mark: |:white_check_mark: | +| Cab be Redeclared? | :x: | :x: | :white_check_mark: | +| Block Scope | :white_check_mark: |:white_check_mark: | :x: | +| Function Scope | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| Stored in Global Scope | :x: | :x: | :white_check_mark: |