Skip to content

Instantly share code, notes, and snippets.

@ucguy4u
Last active October 30, 2020 07:17
Show Gist options
  • Save ucguy4u/79270ee38cf67db7626c3b783c071d80 to your computer and use it in GitHub Desktop.
Save ucguy4u/79270ee38cf67db7626c3b783c071d80 to your computer and use it in GitHub Desktop.
Loading the javascript file using blank html
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>An empty page</title>
<script src="script.js" defer></script>
</head>
<body>
</body>
</html>
// Regular function, called explicitly by name:
function multiply() {
var result = 3 * 4;
console.log("3 multiplied by 4 is ", result);
}
multiply();
// Anonymous function stored in variable.
// Invoked by calling the variable as a function:
var divided = function() {
var result = 3 / 4;
console.log("3 divided by 4 is ", result);
}
divided();
// Immediately Invoked Function Expression.
// Runs as soon as the browser finds it:
(function() {
var result = 12 / 0.75;
console.log("12 divided by 0.75 is ", result);
}())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment