guest271314 (2019-06-15T21:50:02.000Z)
guest271314 at gmail.com (2019-06-15T22:13:35.802Z)
> It doesn’t matter what the *value* of ‘y’ is, just what the lexical name of `y` is. `nameof` wouldn’t refer to `y` as an expression, its just pointing to the identifier. Was not referring to the _value_ of ```y```. At that point in the example code ``` const x = nameof y; // "y" const y = 1; ``` the identifer ```y``` does not exist. Was there an expected presumption that ```y``` was defined _globally_ in the code prior to the ```const y = 1;``` declaration at the next line (which would be a _different_ ```y``` variable than the variable on the next line declared with ```const```)? Does the example code actually expect the ```const``` declaration ```y``` on the next line to be capable of being referenced on the current line _before_ the declaration ("initialization") on the next line occurs in the code? A variable declared using ```const``` cannot be referenced before "lexical declaration" or "initialization". That fact can be utilized for an alternative approach to meet requirement of "Case 1. Function guard.". Tested at Chromium 76 and Firefox 69. Have not used MS browser (or browserstack) in some time. Have not tried the code at Safari either, though the code is capable of adjustment for any JavaScript environment which throws a ```ReferenceError``` under the same case (referencing ```const``` variable _before_ declaration or initialization) ``` function func1(param1, param2, param3, userName, param4, param5) { if (userName === undefined) { try { // throws ReferenceError // Firefox 69: ReferenceError: "can't access lexical declaration `userName' before initialization" // Chromium 76: ReferenceError: Cannot access 'userName' before initialization const userName = userName; } catch (e) { // match identifier at Firefox, Chromium ReferenceError message // adjust RegExp for IE/Edge, Safari, etc. const nameof = e.message.match(/(?!`|')[^\s]+(?=')/g).pop(); throw new Error(`"Argument cannot be null: ${nameof}"`); } } else { // do stuff console.log(userName); } } try { func1(1, 2, 3); // throws error } catch (e) { console.error(e); // get name of variable identifier } try { func1(1, 2, 3, 4); // logs userName at console } catch (e) { console.error(e); // should not be reached } ```
guest271314 at gmail.com (2019-06-15T22:02:38.487Z)
> It doesn’t matter what the *value* of ‘y’ is, just what the lexical name of `y` is. `nameof` wouldn’t refer to `y` as an expression, its just pointing to the identifier. Was not referring to the _value_ of ```y```. At that point in the example code ``` const x = nameof y; // "y" const y = 1; ``` the identifer ```y``` does not exist. Was there an expected presumption that ```y``` was defined _globally_ in the code prior to the ```const y = 1;``` declaration at the next line (which would be a _different_ ```y``` variable than the variable on the next line declared with ```const```)? Does the example code actually expect the ```const``` declaration ```y``` on the next line to be capable of being referenced on the current line _before_ the declaration ("initialization") on the next line occurs in the code? A variable declared using ```const``` cannot be referenced before "lexical declaration" or "initialization". That fact can be utilized for an alternative approach to meet requirement of "Case 1. Function guard.". Tested at Chromium 76 and Firefox 69. Have not used MS browser (or browserstack) in some time. Have not tried the code at Safari either, though the code is capable of adjustment for any JavaScript environment which throws a ```ReferenceError``` under the same case ``` function func1(param1, param2, param3, userName, param4, param5) { if (userName === undefined) { try { // throws ReferenceError // Firefox 69: ReferenceError: "can't access lexical declaration `userName' before initialization" // Chromium 76: ReferenceError: Cannot access 'userName' before initialization const userName = userName; } catch (e) { // match identifier at Firefox, Chromium ReferenceError message // adjust RegExp for IE/Edge, Safari, etc. const nameof = e.message.match(/(?!`|')[^\s]+(?=')/g).pop(); throw new Error(`"Argument cannot be null: ${nameof}"`); } } else { // do stuff console.log(userName); } } try { func1(1, 2, 3); // throws error } catch (e) { console.error(e); // get name of variable identifier } try { func1(1, 2, 3, 4); // logs userName at console } catch (e) { console.error(e); // should not be reached } ```
guest271314 at gmail.com (2019-06-15T21:59:24.445Z)
> It doesn’t matter what the *value* of ‘y’ is, just what the lexical name of `y` is. `nameof` wouldn’t refer to `y` as an expression, its just pointing to the identifier. Was not referring to the _value_ of ```y```. At that point in the example code ``` const x = nameof y; // "y" const y = 1; ``` the identifer ```y``` does not exist. Was there an expected presumption that ```y``` was defined _globally_ in the code prior to the ```const y = 1;``` declaration at the next line (which would be a _different_ ```y``` variable than the variable on the next line declared with ```const```)? Does the example code actually expect the ```const``` declaration ```y``` on the next line to be capable of being referenced before the declaration ("initialization")? A variable declared using ```const``` cannot be referenced before "lexical declaration" or "initialization". That fact can be utilized for an alternative approach to meet requirement of "Case 1. Function guard.". Tested at Chromium 76 and Firefox 69. Have not used MS browser (or browserstack) in some time. Have not tried the code at Safari either, though the code is capable of adjustment for any JavaScript environment which throws a ```ReferenceError``` under the same case ``` function func1(param1, param2, param3, userName, param4, param5) { if (userName === undefined) { try { // throws ReferenceError // Firefox 69: ReferenceError: "can't access lexical declaration `userName' before initialization" // Chromium 76: ReferenceError: Cannot access 'userName' before initialization const userName = userName; } catch (e) { // match identifier at Firefox, Chromium ReferenceError message // adjust RegExp for IE/Edge, Safari, etc. const nameof = e.message.match(/(?!`|')[^\s]+(?=')/g).pop(); throw new Error(`"Argument cannot be null: ${nameof}"`); } } else { // do stuff console.log(userName); } } try { func1(1, 2, 3); // throws error } catch (e) { console.error(e); // get name of variable identifier } try { func1(1, 2, 3, 4); // logs userName at console } catch (e) { console.error(e); // should not be reached } ```
guest271314 at gmail.com (2019-06-15T21:54:52.615Z)
> It doesn’t matter what the *value* of ‘y’ is, just what the lexical name of `y` is. `nameof` wouldn’t refer to `y` as an expression, its just pointing to the identifier. Was not referring to the _value_ of ```y```. At that point in the example code ``` const x = nameof y; // "y" const y = 1; ``` the identifer ```y``` does not exist. That is, unless there was an expected presumption that ```y``` was defined _globally_ prior to the ```const y = 1;``` declaration at the next line - not referring to a variable that does not yet exist on the next line? A variable declared using ```const``` cannot be referenced before "lexical declaration" or "initialization". That fact can be utilized for an alternative approach to meet requirement of "Case 1. Function guard.". Tested at Chromium 76 and Firefox 69. Have not used MS browser (or browserstack) in some time. Have not tried the code at Safari either, though the code is capable of adjustment for any JavaScript environment which throws a ```ReferenceError``` under the same case ``` function func1(param1, param2, param3, userName, param4, param5) { if (userName === undefined) { try { // throws ReferenceError // Firefox 69: ReferenceError: "can't access lexical declaration `userName' before initialization" // Chromium 76: ReferenceError: Cannot access 'userName' before initialization const userName = userName; } catch (e) { // match identifier at Firefox, Chromium ReferenceError message // adjust RegExp for IE/Edge, Safari, etc. const nameof = e.message.match(/(?!`|')[^\s]+(?=')/g).pop(); throw new Error(`"Argument cannot be null: ${nameof}"`); } } else { // do stuff console.log(userName); } } try { func1(1, 2, 3); // throws error } catch (e) { console.error(e); // get name of variable identifier } try { func1(1, 2, 3, 4); // logs userName at console } catch (e) { console.error(e); // should not be reached } ```
guest271314 at gmail.com (2019-06-15T21:52:06.196Z)
> It doesn’t matter what the *value* of ‘y’ is, just what the lexical name of `y` is. `nameof` wouldn’t refer to `y` as an expression, its just pointing to the identifier. Was not referring to the _value_ of ```y```. At that point in the example code the identifer ```y``` does not exist. That is, unless there was an expected presumption that ```y``` was defined globally prior to the ```const y = 1;``` declaration at the next line. Even then a variable declared using ```const``` cannot be referenced before "lexical declaration" or "initialization". That fact can be utilized for an alternative approach to meet requirement of "Case 1. Function guard.". Tested at Chromium 76 and Firefox 69. Have not used MS browser (or browserstack) in some time. Have not tried the code at Safari either, though the code is capable of adjustment for any JavaScript environment which throws a ```ReferenceError``` under the same case ``` function func1(param1, param2, param3, userName, param4, param5) { if (userName === undefined) { try { // throws ReferenceError // Firefox 69: ReferenceError: "can't access lexical declaration `userName' before initialization" // Chromium 76: ReferenceError: Cannot access 'userName' before initialization const userName = userName; } catch (e) { // match identifier at Firefox, Chromium ReferenceError message // adjust RegExp for IE/Edge, Safari, etc. const nameof = e.message.match(/(?!`|')[^\s]+(?=')/g).pop(); throw new Error(`"Argument cannot be null: ${nameof}"`); } } else { // do stuff console.log(userName); } } try { func1(1, 2, 3); // throws error } catch (e) { console.error(e); // get name of variable identifier } try { func1(1, 2, 3, 4); // logs userName at console } catch (e) { console.error(e); // should not be reached } ```