Created
June 26, 2017 07:55
-
-
Save justinestrada/2480844396ab6921317a60d684fbcb80 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/qipizo
This file contains 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> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
// Weak typing in JS | |
var container = 'Text'; | |
console.log( typeof container ); | |
container = 2; | |
console.log( typeof container ); | |
container = true; | |
console.log( typeof container ); | |
container = { id: 1, title: 'Hello' }; | |
console.log( typeof container ); | |
// Logical Operators | |
var user = { | |
id: 1, | |
name: 'Zac', | |
role: 'admin', | |
loggedIn: true | |
}, | |
post = { | |
id: 777, | |
status: 'private', | |
authorId: 1 | |
}; | |
if ( 'admin' === user.role && post.authorId === user.id ) { | |
console.log( 'Edit your posts.' ); | |
} | |
// Conditional Operator | |
var monkey = { | |
hasNoBanana: true | |
}, | |
shouldWeFeedMonkey; | |
shouldWeFeedMonkey = ( monkey.hasNoBanana ) ? "Yes feed monkey" : "No dont feed monkey"; | |
console.log( shouldWeFeedMonkey ); | |
// if else statement | |
var user = { | |
role: 'subscriber', | |
username: 'test' | |
}; | |
if ( 'admin' === user.role ) { | |
console.log( 'Show admin' ); | |
} else if ( 'editor' === user.role ) { | |
console.log( 'Show all posts' ); | |
} else if ( 'author' === user.role ) { | |
console.log( 'Show author posts' ); | |
} else { | |
console.log( 'Please contact admin' ); | |
} | |
// if else statement | |
var user = { | |
role: 'editor', | |
username: 'test' | |
}; | |
switch ( user.role ) { | |
case 'admin': | |
console.log( 'Show admin' ); | |
break; | |
case 'editor': | |
console.log( 'Show all posts' ); | |
break; | |
case 'author': | |
console.log( 'Show author posts' ); | |
break; | |
default: | |
console.log( 'Please contact admin' ); | |
} | |
// For loop | |
for ( var i = 1, max = 6; i < max; i++ ) { | |
console.log( 'Display post #' + i ); | |
} | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">// Weak typing in JS | |
var container = 'Text'; | |
console.log( typeof container ); | |
container = 2; | |
console.log( typeof container ); | |
container = true; | |
console.log( typeof container ); | |
container = { id: 1, title: 'Hello' }; | |
console.log( typeof container ); | |
// Logical Operators | |
var user = { | |
id: 1, | |
name: 'Zac', | |
role: 'admin', | |
loggedIn: true | |
}, | |
post = { | |
id: 777, | |
status: 'private', | |
authorId: 1 | |
}; | |
if ( 'admin' === user.role && post.authorId === user.id ) { | |
console.log( 'Edit your posts.' ); | |
} | |
// Conditional Operator | |
var monkey = { | |
hasNoBanana: true | |
}, | |
shouldWeFeedMonkey; | |
shouldWeFeedMonkey = ( monkey.hasNoBanana ) ? "Yes feed monkey" : "No dont feed monkey"; | |
console.log( shouldWeFeedMonkey ); | |
// if else statement | |
var user = { | |
role: 'subscriber', | |
username: 'test' | |
}; | |
if ( 'admin' === user.role ) { | |
console.log( 'Show admin' ); | |
} else if ( 'editor' === user.role ) { | |
console.log( 'Show all posts' ); | |
} else if ( 'author' === user.role ) { | |
console.log( 'Show author posts' ); | |
} else { | |
console.log( 'Please contact admin' ); | |
} | |
// if else statement | |
var user = { | |
role: 'editor', | |
username: 'test' | |
}; | |
switch ( user.role ) { | |
case 'admin': | |
console.log( 'Show admin' ); | |
break; | |
case 'editor': | |
console.log( 'Show all posts' ); | |
break; | |
case 'author': | |
console.log( 'Show author posts' ); | |
break; | |
default: | |
console.log( 'Please contact admin' ); | |
} | |
// For loop | |
for ( var i = 1, max = 6; i < max; i++ ) { | |
console.log( 'Display post #' + i ); | |
} | |
</script></body> | |
</html> |
This file contains 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
// Weak typing in JS | |
var container = 'Text'; | |
console.log( typeof container ); | |
container = 2; | |
console.log( typeof container ); | |
container = true; | |
console.log( typeof container ); | |
container = { id: 1, title: 'Hello' }; | |
console.log( typeof container ); | |
// Logical Operators | |
var user = { | |
id: 1, | |
name: 'Zac', | |
role: 'admin', | |
loggedIn: true | |
}, | |
post = { | |
id: 777, | |
status: 'private', | |
authorId: 1 | |
}; | |
if ( 'admin' === user.role && post.authorId === user.id ) { | |
console.log( 'Edit your posts.' ); | |
} | |
// Conditional Operator | |
var monkey = { | |
hasNoBanana: true | |
}, | |
shouldWeFeedMonkey; | |
shouldWeFeedMonkey = ( monkey.hasNoBanana ) ? "Yes feed monkey" : "No dont feed monkey"; | |
console.log( shouldWeFeedMonkey ); | |
// if else statement | |
var user = { | |
role: 'subscriber', | |
username: 'test' | |
}; | |
if ( 'admin' === user.role ) { | |
console.log( 'Show admin' ); | |
} else if ( 'editor' === user.role ) { | |
console.log( 'Show all posts' ); | |
} else if ( 'author' === user.role ) { | |
console.log( 'Show author posts' ); | |
} else { | |
console.log( 'Please contact admin' ); | |
} | |
// if else statement | |
var user = { | |
role: 'editor', | |
username: 'test' | |
}; | |
switch ( user.role ) { | |
case 'admin': | |
console.log( 'Show admin' ); | |
break; | |
case 'editor': | |
console.log( 'Show all posts' ); | |
break; | |
case 'author': | |
console.log( 'Show author posts' ); | |
break; | |
default: | |
console.log( 'Please contact admin' ); | |
} | |
// For loop | |
for ( var i = 1, max = 6; i < max; i++ ) { | |
console.log( 'Display post #' + i ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment