Created
July 13, 2023 17:36
-
-
Save prof3ssorSt3v3/4a1ecfb307ca636e315d038b9cdd95fc to your computer and use it in GitHub Desktop.
code from video about checking for variable existence
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<title>Variable Existence</title> | |
<script src="index.js" type="module"></script> | |
</head> | |
<body> | |
<header> | |
<h1>Checking for Variable Existence</h1> | |
</header> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { NAME, frodo } from './mod.js'; | |
//gimli doesn't exist in mod.js | |
const log = console.log; | |
let num1 = 42; | |
let str1 = 'Steve'; | |
let obj1 = { a: 123 }; | |
let arr1 = [1, 2, 3]; | |
const f1 = function () { | |
console.log('f1 function'); | |
}; | |
try { | |
f2(); | |
} catch (err) { | |
log('error'); | |
if (err.name === 'ReferenceError') { | |
log('f2 does not exist'); | |
log(err.message); | |
} | |
} | |
// log(typeof NAME); | |
// log(typeof frodo); | |
// log(typeof gimli); | |
// var num2 = 99; | |
// var f2 = function () { | |
// console.log('f2 function'); | |
// }; | |
// function f3() { | |
// console.log('f3 function'); | |
// } | |
// log(window['num2']); | |
// log(window['f2']); | |
// log('f3' in window); | |
// log(typeof num1); | |
// log(typeof str1); | |
// log(typeof obj1); | |
// log(typeof arr1); | |
// log(typeof f1); | |
// log(typeof num2 === 'undefined'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const NAME = 'Frodo'; | |
export function frodo() { | |
console.log('frodo'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment