Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<button id="myButton"> Hello World! </button>
<script>
var button = document.getElementById("myButton")
function speak(){ alert("hi!") } // this is a function declaration, allowing 'speak' to be used anywhere in the code, even above this line.
//you can also assign an "anonymous function" to a variable name, but this function can only be called below where it was assigned
//var speak = function() { alert("hi!") }
button.onclick = speak
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.