From 6dafa8bd10cff371c5e562fef9347ec2a1c5aa03 Mon Sep 17 00:00:00 2001 From: roeib Date: Thu, 27 Aug 2020 09:40:04 +0300 Subject: [PATCH 01/22] replaceAll --- README.md | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 79bb9eb..6dd261b 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ |30 | [Private class methods and fields](#Private-class-methods-and-fields)| |31 | [Preventing paste into an input field](#Preventing-paste-into-an-input-field)| |32 | [The void operator](#The-void-operator)| +|33 | [replaceAll](#replaceAll)| @@ -660,8 +661,8 @@ pasteBox.onpaste = (e) => { **[⬆ Back to Top](#table-of-contents)** -### The void operator -The void operator evaluates the given expression and then returns undefined. +### replaceAll +the method string.replaceAll(search, replaceWith) replaces all appearances of search string with replaceWith. ```javascript @@ -675,3 +676,43 @@ void anyfunction(); //returns undefined ``` + +**[⬆ Back to Top](#table-of-contents)** +### The void operator +The void operator evaluates the given expression and then returns undefined. +```javascript + + +const str = 'this is a JSsnippets example'; + +const updatedStr = str.replace('example', 'snippet'); // 'this is a JSsnippets snippet' + + +The tricky part is that replace method replaces only the very first match of the substring we have passed: + + +const str = 'this is a JSsnippets example and examples are great'; + +const updatedStr = str.replace('example', 'snippet'); //'this is a JSsnippets snippet and examples are great' + +In order to go through this, we need to use a global regexp instead: + + +const str = 'this is a JSsnippets example and examples are great'; + +const updatedStr = str.replace(/example/g, 'snippet'); //'this is a JSsnippets snippet and snippets are greatr' + +but now we have new friend in town, replaceAll + +const str = 'this is a JSsnippets example and examples are great'; + +const updatedStr = str.replaceAll('example', 'snippet'); //'this is a JSsnippets snippet and snippets are greatr' + +``` + + + + + + + From 3ed5b5f93855cd64acbefcd555f0b65dc8634232 Mon Sep 17 00:00:00 2001 From: roeib Date: Thu, 27 Aug 2020 09:41:00 +0300 Subject: [PATCH 02/22] replace all change --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6dd261b..160449f 100644 --- a/README.md +++ b/README.md @@ -661,8 +661,8 @@ pasteBox.onpaste = (e) => { **[⬆ Back to Top](#table-of-contents)** -### replaceAll -the method string.replaceAll(search, replaceWith) replaces all appearances of search string with replaceWith. +### The void operator +The void operator evaluates the given expression and then returns undefined. ```javascript @@ -678,8 +678,8 @@ void anyfunction(); //returns undefined **[⬆ Back to Top](#table-of-contents)** -### The void operator -The void operator evaluates the given expression and then returns undefined. +### replaceAll +the method string.replaceAll(search, replaceWith) replaces all appearances of search string with replaceWith. ```javascript From 5b5e313d023337fbcd3ecb0f294aa10e80904889 Mon Sep 17 00:00:00 2001 From: roeib Date: Wed, 9 Sep 2020 09:16:00 +0300 Subject: [PATCH 03/22] Required Function Params --- README.md | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 160449f..c63b3b9 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ |31 | [Preventing paste into an input field](#Preventing-paste-into-an-input-field)| |32 | [The void operator](#The-void-operator)| |33 | [replaceAll](#replaceAll)| - +|34 | [Required Function Params](#Required-Function-Params)| **[⬆ Back to Top](#table-of-contents)** @@ -711,6 +711,28 @@ const updatedStr = str.replaceAll('example', 'snippet'); //'this is a JSsnippets ``` +**[⬆ Back to Top](#table-of-contents)** +### Required Function Params +Expanding on the default parameter technique, we can mark a parameter as mandatory + +```javascript +const isRequired = () => { + throw new Error( 'This is a mandatory parameter.' ); +} + + +const getPage = ( pageName = 'Jssnippets', url = isRequired() ) => { + return `${pageName} ${url}`; +} + +console.log(getPage()); + +//In the above code, url will be undefined and that will try to set the default value for it which is the isRequired() function. It will throw an error as, + +//Uncaught error: This is a mandatory parameter. +//at isRequired + +``` From 48afc0ddd55ad4258b441977bea3d34cefe43173 Mon Sep 17 00:00:00 2001 From: roeib Date: Wed, 23 Sep 2020 09:19:05 +0300 Subject: [PATCH 04/22] Get input value as a number --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index c63b3b9..c417bad 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,8 @@ |32 | [The void operator](#The-void-operator)| |33 | [replaceAll](#replaceAll)| |34 | [Required Function Params](#Required-Function-Params)| +|35 | [Get input value as a number](#Get-input-value-as-a-number)| + **[⬆ Back to Top](#table-of-contents)** @@ -737,4 +739,18 @@ console.log(getPage()); +**[⬆ Back to Top](#table-of-contents)** +### Get input value as a number + +```javascript + + + +function checkMyType(event){ + + console.log(typeof event.target.value) // string + console.log(typeof event.target.valueAsNumber ) // number + +} +``` From bae6599b2aeabca1736a47cf3f13d7b69b8b84f4 Mon Sep 17 00:00:00 2001 From: roeib Date: Tue, 6 Oct 2020 10:39:29 +0300 Subject: [PATCH 05/22] reduceRight --- README.md | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c417bad..aa8bc05 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # JavaScript-snippets -> Click :star:if you like the project. Pull Request are highly appreciated. Follow us on [Facebook](https://www.facebook.com/snippetsJS) +> Click :star: if you like the project. Pull Request are highly appreciated. Follow us on [Facebook](https://www.facebook.com/snippetsJS) ### Table of Contents | No. | Questions | @@ -39,6 +39,7 @@ |33 | [replaceAll](#replaceAll)| |34 | [Required Function Params](#Required-Function-Params)| |35 | [Get input value as a number](#Get-input-value-as-a-number)| +|36 | [reduceRight](#reduceRight)| @@ -753,4 +754,24 @@ function checkMyType(event){ } + +``` +**[⬆ Back to Top](#table-of-contents)** +### reduceRight + +```javascript + +const arr = ["a", "b", "c", "d", "e"] + +const reduceArray = arr.reduce((acc, current) => { + return acc + current +}, "") +//return abcde + +const reduceRightArray = arr.reduceRight((acc, current) => { + return acc + current +}, "") +//return edcba + ``` + From f3233ab7ddbcc58a10638b0902cf8982e5265e70 Mon Sep 17 00:00:00 2001 From: roeib Date: Tue, 27 Oct 2020 10:48:19 +0200 Subject: [PATCH 06/22] Abort Fetch --- README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/README.md b/README.md index aa8bc05..88f2009 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,10 @@ |34 | [Required Function Params](#Required-Function-Params)| |35 | [Get input value as a number](#Get-input-value-as-a-number)| |36 | [reduceRight](#reduceRight)| +|37 | [Abort Fetch](#AbortFetch)| + + + @@ -775,3 +779,34 @@ const reduceRightArray = arr.reduceRight((acc, current) => { ``` + + +``` +**[⬆ Back to Top](#table-of-contents)** +### Abort Fetch + +```javascript + + +//HTML + + + +//JS +let controller; + +document.querySelector('#download').addEventListener('click', () => { + controller = new AbortController(); + const signal = controller.signal; + fetch('https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-576p.mp4', {signal}) + .then(() => console.log('done')); +}); + +document.querySelector('#abort').addEventListener('click', function() { + controller.abort(); +}); + +``` + + + From aecd69b70fc4238b347560a46158246161d60fc0 Mon Sep 17 00:00:00 2001 From: roeib Date: Tue, 27 Oct 2020 10:49:08 +0200 Subject: [PATCH 07/22] typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 88f2009..c972f2b 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ |34 | [Required Function Params](#Required-Function-Params)| |35 | [Get input value as a number](#Get-input-value-as-a-number)| |36 | [reduceRight](#reduceRight)| -|37 | [Abort Fetch](#AbortFetch)| +|37 | [Abort Fetch](#Abort-Fetch)| From 1448ea5fab602b00a68356c25c67d43bfdab40e9 Mon Sep 17 00:00:00 2001 From: roeib Date: Tue, 27 Oct 2020 10:49:47 +0200 Subject: [PATCH 08/22] Update README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index c972f2b..fde7f3e 100644 --- a/README.md +++ b/README.md @@ -780,8 +780,6 @@ const reduceRightArray = arr.reduceRight((acc, current) => { ``` - -``` **[⬆ Back to Top](#table-of-contents)** ### Abort Fetch From 7ec664906abbeb164d9c3b3db7d0ade523eaa3c9 Mon Sep 17 00:00:00 2001 From: roeib Date: Tue, 10 Nov 2020 09:47:24 +0200 Subject: [PATCH 09/22] change object value which is inside an array --- README.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/README.md b/README.md index fde7f3e..97ef1e7 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,10 @@ |35 | [Get input value as a number](#Get-input-value-as-a-number)| |36 | [reduceRight](#reduceRight)| |37 | [Abort Fetch](#Abort-Fetch)| +|38 | [How to change the value of an object which is inside an array](#How-to-change-the-value-of-an-object-which-is-inside-an-array)| + + + @@ -807,4 +811,38 @@ document.querySelector('#abort').addEventListener('click', function() { ``` +**[⬆ Back to Top](#table-of-contents)** +### How to change the value of an object which is inside an array + +```javascript + +const state = [ + { + userId: 1, + name: "JSSnippets", + isOwner: false, + }, + { + userId: 2, + name: "React", + isOwner: false, + }, + { + userId: 3, + name: "Vue", + isOwner: false, + }, + { + userId: 4, + name: "Angular", + isOwner: false, + }, +]; + +const newState = state.map((obj) => + obj.name === "JSSnippets" ? { ...obj, isOwner: true } : obj +); + +``` + From 45748db3131538e7713b5a3727c5053c86763010 Mon Sep 17 00:00:00 2001 From: roeib Date: Tue, 19 Jan 2021 22:59:05 +0200 Subject: [PATCH 10/22] Numeric separators --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 97ef1e7..b499b95 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,8 @@ |36 | [reduceRight](#reduceRight)| |37 | [Abort Fetch](#Abort-Fetch)| |38 | [How to change the value of an object which is inside an array](#How-to-change-the-value-of-an-object-which-is-inside-an-array)| +|39 | [Numeric separators allow us to improve our code readability](#Numeric-separators-allow-us-to-improve-our-code-readability)| + @@ -845,4 +847,18 @@ const newState = state.map((obj) => ``` +**[⬆ Back to Top](#table-of-contents)** +### Numeric separators allow us to improve our code readability + +```javascript + +100_000_000 === 100000000 // true + +300_000 === 300000 //true + +``` + + + + From 4f0ef948188271fa35e8e31dc306ba5ac51ab373 Mon Sep 17 00:00:00 2001 From: roeib Date: Wed, 27 Jan 2021 08:45:24 +0200 Subject: [PATCH 11/22] pay attention when using every --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index b499b95..d0b6b03 100644 --- a/README.md +++ b/README.md @@ -862,3 +862,24 @@ const newState = state.map((obj) => +**[⬆ Back to Top](#table-of-contents)** +### pay attention when using every + +Calling this method on an empty array will return true for any condition! + + +```javascript + +const arr = [] +const result = arr.every(x=> x==5) +console.log(result) //true + +``` + + + + + + + + From 76efd6bce3f93c969c9cc18234b0f3b2a53cab80 Mon Sep 17 00:00:00 2001 From: roeib Date: Wed, 27 Jan 2021 08:46:46 +0200 Subject: [PATCH 12/22] add title --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d0b6b03..9ace570 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ |37 | [Abort Fetch](#Abort-Fetch)| |38 | [How to change the value of an object which is inside an array](#How-to-change-the-value-of-an-object-which-is-inside-an-array)| |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)| From aab98f5484371a1e2d37613aacddbcb88e7bc009 Mon Sep 17 00:00:00 2001 From: roeib Date: Mon, 22 Mar 2021 13:40:35 +0200 Subject: [PATCH 13/22] convert an array of key-value into an object --- README.md | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9ace570..fb62f64 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # JavaScript-snippets -> Click :star: if you like the project. Pull Request are highly appreciated. Follow us on [Facebook](https://www.facebook.com/snippetsJS) +> Click :star: if you like the project. Pull Request are highly appreciated. Follow us on [Facebook](https://www.facebook.com/snippetsJS) ### Table of Contents | No. | Questions | @@ -44,7 +44,7 @@ |38 | [How to change the value of an object which is inside an array](#How-to-change-the-value-of-an-object-which-is-inside-an-array)| |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)| @@ -880,6 +880,27 @@ console.log(result) //true +**[⬆ Back to Top](#table-of-contents)** +### How to convert an array of key-value tuples into an object + + +```javascript +const JSarr = [ + ['name', 'JSsnippets'], + ['address', 'worldwide'], + ['year', '2018'], + ['followers', '15000'] + +]; + +const obj = Object.fromEntries(JSarr); +//{ +// "name": "JSsnippets", +// "address": "worldwide", +// "year": "2018", +// "followers": "15000" +//} +``` From d9fb76816b1d4291bf109707bb2d9f77dbb84bd0 Mon Sep 17 00:00:00 2001 From: roeib Date: Wed, 14 Apr 2021 07:51:32 +0300 Subject: [PATCH 14/22] 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 15/22] 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 16/22] 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 17/22] 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 18/22] 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 19/22] 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 20/22] 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 21/22] 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 22/22] 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: |