Skip to content

Instantly share code, notes, and snippets.

@ndonolli
Forked from anonymous/index.html
Last active June 27, 2016 01:49
Show Gist options
  • Save ndonolli/7ea2ed66bac93578879bb441bbe5d840 to your computer and use it in GitHub Desktop.
Save ndonolli/7ea2ed66bac93578879bb441bbe5d840 to your computer and use it in GitHub Desktop.
JS Bin// source https://jsbin.com/wabacu
<!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">
/*
=========
DATATYPES
=========
We want our javascript program to store and manipulate
data. This data is atomically stored within the
program's memory as bits - tiny units of information that
have binary states: being on or off. However, we want
these bits to represent data that may be more relevant
to us humans. Data like numbers, text, and even other
programs. This is why in javascript there are several
different DATATYPES, which can be recognized by the
javascript engine and hold different properties.
The list of datatypes in javascript are as follows:
* Number
* String
* Boolean
* Array
* Object
* Function
* undefined
* null
* NaN
* Infinity (and -Infinity)
Numbers
-------
Numbers in javascript are simply numerical values.
They can be stored within a variable and changed with
mathematical operations.
*/
var myNumber = 7;
// They do not have to be integers - floating point
// values are also recognized as numbers.
var myFloatingNumber = 7.24;
// We can determine the datatype of a variable by
// using the 'typeof' keyword.
console.log(typeof myNumber);
// > "number"
/*
Strings
-------
Words or a collection of characters is stored as the
datatype 'Strings'. Strings must be declared within
single or double quotation marks.
*/
var myString = 'string bean';
console.log(typeof myString);
// > "string"
// All text encapsulated within the quotes (except
// escape characters) will make up the string.
// Note that numerals can also be strings.
var myNumberString = '88';
/*
Boolean
-------
Boolean values evaluate to either true or false. They
are useful when using conditionals in the program.
*/
var myBoolean = true;
console.log(typeof myBoolean);
// > "boolean"
// Expressions that evaluate to boolean values are
// also treated as boolean datatypes.
var myBoolean = (5 > 2);
console.log(myBoolean);
// > true
console.log(typeof myBoolean);
// > "boolean"
/*
Undefined and null
------------------
These two datatypes refer to the absence of some sort
of data. A variable may be undefined if the variable
is declared but not initialized. A variable is null
when it points to an address or object that does not
exist, or it contains no meaningful data.
*/
var myUndefined;
console.log(typeof myUndefined);
// > "undefined"
var myNull = null;
console.log(10 * myNull);
// > 0
/*
So far, we have seen examples of primitive data types
in javascript. Primitive data types are simple and
cannot be changed or altered once initialized. We
call them immutable values for this reason. If a
variable is reassigned..
*/
var myPrimitive = 'spam';
myPrimitive = 'spam and eggs';
/*
..it may look as if we simply changed the value of
myPrimitive. But in reality, the javascript engine
destroys the old value 'spam' and reinitializes a
new myPrimitive with the value 'spam and eggs'.
There exist complex datatypes in javascript that can
be manipulated and altered. Unlike primitive data
types, these datatypes are mutable.
Arrays
------
An array is a collection of data that is ordered and
can be accessed with an index value. It is notated
in javascript with square brackets ( [] ).
*/
var myArray = ['cat','dog','Geoffrey'];
// Elements in the array can be accessed by their
// index value, which begins at 0 and counts up
// sequentially.
console.log(myArray[0]);
// > 'cat'
console.log(myArray[2]);
// > 'Geoffrey'
/*
Objects
-------
Objects are a complex data type that can store other
properties and methods. Objects can be initialized
to a variable and are notated with curly (moustache)
braces ( {} ).
*/
var myObject = {};
console.log(typeof myObject);
// > "object"
// Objects can be used to store properties, and these
// properties can be accessed using dot notation.
var sweetCar = {
wheels: 4,
color: "bitchin red",
};
console.log(sweetCar.wheels);
// > 4
console.log(sweetCar.color);
// > "bitchin red"
// Information in the object is formatted and stored
// as (key: value), and keys can be used in the dot
// notation to access its value. Values do not have
// to be primitive data types.
/*
NaN and Infinity
----------------
These are two special numeric data types that relate
to numbers and mathematics but don't necessarily
behave like them. NaN stands for 'not a number' and
is used in javascript to represent numeric values
outside the limit of what can be expressed within the
confines of the programming language. This includes
imaginary numbers, for example.
*/
console.log(Math.sqrt(-5));
// > NaN
// Infinity represents exactly that: infinity. It
// can be used the same way infinity is used in math.
console.log(Infinity + 1);
// > Infinity
</script>
<script id="jsbin-source-javascript" type="text/javascript">/*
=========
DATATYPES
=========
We want our javascript program to store and manipulate
data. This data is atomically stored within the
program's memory as bits - tiny units of information that
have binary states: being on or off. However, we want
these bits to represent data that may be more relevant
to us humans. Data like numbers, text, and even other
programs. This is why in javascript there are several
different DATATYPES, which can be recognized by the
javascript engine and hold different properties.
The list of datatypes in javascript are as follows:
* Number
* String
* Boolean
* Array
* Object
* Function
* undefined
* null
* NaN
* Infinity (and -Infinity)
Numbers
-------
Numbers in javascript are simply numerical values.
They can be stored within a variable and changed with
mathematical operations.
*/
var myNumber = 7;
// They do not have to be integers - floating point
// values are also recognized as numbers.
var myFloatingNumber = 7.24;
// We can determine the datatype of a variable by
// using the 'typeof' keyword.
console.log(typeof myNumber);
// > "number"
/*
Strings
-------
Words or a collection of characters is stored as the
datatype 'Strings'. Strings must be declared within
single or double quotation marks.
*/
var myString = 'string bean';
console.log(typeof myString);
// > "string"
// All text encapsulated within the quotes (except
// escape characters) will make up the string.
// Note that numerals can also be strings.
var myNumberString = '88';
/*
Boolean
-------
Boolean values evaluate to either true or false. They
are useful when using conditionals in the program.
*/
var myBoolean = true;
console.log(typeof myBoolean);
// > "boolean"
// Expressions that evaluate to boolean values are
// also treated as boolean datatypes.
var myBoolean = (5 > 2);
console.log(myBoolean);
// > true
console.log(typeof myBoolean);
// > "boolean"
/*
Undefined and null
------------------
These two datatypes refer to the absence of some sort
of data. A variable may be undefined if the variable
is declared but not initialized. A variable is null
when it points to an address or object that does not
exist, or it contains no meaningful data.
*/
var myUndefined;
console.log(typeof myUndefined);
// > "undefined"
var myNull = null;
console.log(10 * myNull);
// > 0
/*
So far, we have seen examples of primitive data types
in javascript. Primitive data types are simple and
cannot be changed or altered once initialized. We
call them immutable values for this reason. If a
variable is reassigned..
*/
var myPrimitive = 'spam';
myPrimitive = 'spam and eggs';
/*
..it may look as if we simply changed the value of
myPrimitive. But in reality, the javascript engine
destroys the old value 'spam' and reinitializes a
new myPrimitive with the value 'spam and eggs'.
There exist complex datatypes in javascript that can
be manipulated and altered. Unlike primitive data
types, these datatypes are mutable.
Arrays
------
An array is a collection of data that is ordered and
can be accessed with an index value. It is notated
in javascript with square brackets ( [] ).
*/
var myArray = ['cat','dog','Geoffrey'];
// Elements in the array can be accessed by their
// index value, which begins at 0 and counts up
// sequentially.
console.log(myArray[0]);
// > 'cat'
console.log(myArray[2]);
// > 'Geoffrey'
/*
Objects
-------
Objects are a complex data type that can store other
properties and methods. Objects can be initialized
to a variable and are notated with curly (moustache)
braces ( {} ).
*/
var myObject = {};
console.log(typeof myObject);
// > "object"
// Objects can be used to store properties, and these
// properties can be accessed using dot notation.
var sweetCar = {
wheels: 4,
color: "bitchin red",
};
console.log(sweetCar.wheels);
// > 4
console.log(sweetCar.color);
// > "bitchin red"
// Information in the object is formatted and stored
// as (key: value), and keys can be used in the dot
// notation to access its value. Values do not have
// to be primitive data types.
/*
NaN and Infinity
----------------
These are two special numeric data types that relate
to numbers and mathematics but don't necessarily
behave like them. NaN stands for 'not a number' and
is used in javascript to represent numeric values
outside the limit of what can be expressed within the
confines of the programming language. This includes
imaginary numbers, for example.
*/
console.log(Math.sqrt(-5));
// > NaN
// Infinity represents exactly that: infinity. It
// can be used the same way infinity is used in math.
console.log(Infinity + 1);
// > Infinity
</script></body>
</html>
/*
=========
DATATYPES
=========
We want our javascript program to store and manipulate data. This data is atomically stored
within the program's memory as bits - tiny units of information that have binary states:
being on or off. However, we want these bits to represent data that may be more relevant
to us humans. Data like numbers, text, and even other programs. This is why in javascript
there are several different DATATYPES, which can be recognized by the javascript engine and
hold different properties.
The list of datatypes in javascript are as follows:
* Number
* String
* Boolean
* Array
* Object
* Function
* undefined
* null
* NaN
* Infinity (and -Infinity)
Numbers
-------
Numbers in javascript are simply numerical values. They can be stored within a variable and
changed with mathematical operations.
*/
var myNumber = 7;
// They do not have to be integers - floating point values are also recognized as numbers.
var myFloatingNumber = 7.24;
// We can determine the datatype of a variable by using the 'typeof' keyword.
console.log(typeof myNumber);
// > "number"
/*
Strings
-------
Words or a collection of characters is stored as the datatype 'Strings'. Strings must be
declared within single or double quotation marks.
*/
var myString = 'string bean';
console.log(typeof myString);
// > "string"
// All text encapsulated within the quotes (except escape characters) will make up the string.
// Note that numerals can also be strings.
var myNumberString = '88';
/*
Boolean
-------
Boolean values evaluate to either true or false. They are useful when using conditionals
in the program.
*/
var myBoolean = true;
console.log(typeof myBoolean);
// > "boolean"
// Expressions that evaluate to boolean values are also treated as boolean datatypes.
var myBoolean = (5 > 2);
console.log(myBoolean);
// > true
console.log(typeof myBoolean);
// > "boolean"
/*
Undefined and null
------------------
These two datatypes refer to the absence of some sort of data. A variable may be undefined
if the variable is declared but not initialized. A variable is null when it points to an
address or object that does not exist, or it contains no meaningful data.
*/
var myUndefined;
console.log(typeof myUndefined);
// > "undefined"
var myNull = null;
console.log(10 * myNull);
// > 0
/*
So far, we have seen examples of primitive data types in javascript. Primitive data types
are simple and cannot be changed or altered once initialized. We call them immutable
values for this reason. If a variable is reassigned..
*/
var myPrimitive = 'spam';
myPrimitive = 'spam and eggs';
/*
..it may look as if we simply changed the value of myPrimitive. But in reality, the
javascript engine destroys the old value 'spam' and reinitializes a new myPrimitive
with the value 'spam and eggs'.
There exist complex datatypes in javascript that can be manipulated and altered.
Unlike primitive data types, these datatypes are mutable.
Arrays
------
An array is a collection of data that is ordered and can be accessed with an index value.
It is notated in javascript with square brackets ( [] ).
*/
var myArray = ['cat','dog','Geoffrey'];
// Elements in the array can be accessed by their index value, which begins at 0 and
// counts up sequentially.
console.log(myArray[0]);
// > 'cat'
console.log(myArray[2]);
// > 'Geoffrey'
// We can alter individual elements in the array as well using bracket notation.
myArray[1] = 'kitten';
console.log(myArray);
// > ['cat', 'kitten', 'Geoffrey']
/*
Objects
-------
Objects are a complex data type that can store other properties and methods. Objects can
be initialized to a variable and are notated with curly (moustache) braces ( {} ).
*/
var myObject = {};
console.log(typeof myObject);
// > "object"
// Objects can be used to store properties, and these properties can be accessed
// using dot notation.
var sweetCar = {
wheels: 4,
paintJob: "bitchin red",
};
console.log(sweetCar.wheels);
// > 4
console.log(sweetCar.paintJob);
// > "bitchin red"
// Information in the object is formatted and stored as (key: value), and keys can be
// used in the dot notation to access its value. Values do not have to be primitive
// data types.
sweetCar.paintJob = 'scorchin yellow'
console.log(sweetCar.paintJob);
// > "scorchin yellow"
/*
NaN and Infinity
----------------
These are two special numeric data types that relate to numbers and mathematics but don't
necessarily behave like them. NaN stands for 'not a number' and is used in javascript to
represent numeric values outside the limit of what can be expressed within the confines of
the programming language. This includes imaginary numbers, for example.
*/
console.log(Math.sqrt(-5));
// > NaN
// Infinity represents exactly that: infinity. It can be used the same way infinity
// is used in math.
console.log(Infinity + 1);
// > Infinity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment