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
var foo = []; | |
foo.push( "a" ); | |
foo.push( "b" ); | |
alert( foo[ 0 ] ); // a | |
alert( foo[ 1 ] ); // b | |
alert( foo.length ); // 2 | |
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
// Creating an object with the constructor: | |
var person1 = new Object; | |
person1.firstName = "John"; | |
person1.lastName = "Doe"; | |
alert( person1.firstName + " " + person1.lastName ); | |
// Creating an object with the object literal syntax: | |
var person2 = { |
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> | |
<head> | |
<script> | |
// Attempting to access an element too early will have unexpected results. | |
var title = document.getElementById( "hello-world" ); | |
console.log( title ); | |
</script> | |
</head> | |
<body> |
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
<!-- Inline code directly on HTML elements being clicked. --> | |
<a href="javascript:alert( 'Hello World' );">Click Me!</a> | |
<button onClick="alert( 'Good Bye World' );">Click Me Too!</button> |
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
<!-- Embed code directly on a web page using script tags. --> | |
<script> | |
alert( "Hello World!" ); | |
</script> |
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
<!-- Code is written in a .js file, included via the script tag src attribute. --> | |
<script src="/path/to/example.js"></script> |
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> | |
<body> | |
<h1>My First Web Page</h1> | |
<p id="demo">My First Paragraph.</p> | |
<script> | |
document.getElementById("demo").innerHTML = "Paragraph changed."; |
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> | |
<body> | |
<h1>JavaScript</h1> | |
<p>Click Date to display current day, date, and time.</p> | |
<button type="button" onclick="myFunction()">Date</button> |
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> | |
<head> | |
<style> | |
.newspaper | |
{ | |
-webkit-column-count:3; /* Chrome, Safari, Opera */ | |
-moz-column-count:3; /* Firefox */ | |
column-count:3; | |
} |
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> | |
<head> | |
<style> | |
div | |
{ | |
width:100px; | |
height:100px; | |
background:red; | |
-webkit-animation:myfirst 5s; /* Chrome, Safari, Opera */ |