Skip to content

Instantly share code, notes, and snippets.

@prof3ssorSt3v3
Created July 13, 2023 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prof3ssorSt3v3/4a1ecfb307ca636e315d038b9cdd95fc to your computer and use it in GitHub Desktop.
Save prof3ssorSt3v3/4a1ecfb307ca636e315d038b9cdd95fc to your computer and use it in GitHub Desktop.
code from video about checking for variable existence
<!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>
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');
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