Skip to content

Instantly share code, notes, and snippets.

@hillbilly300
Created October 27, 2019 15:20
Show Gist options
  • Save hillbilly300/decc762ab9326e66f641de5b2d19bead to your computer and use it in GitHub Desktop.
Save hillbilly300/decc762ab9326e66f641de5b2d19bead to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/sonafal
<!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">
//jshint esnext:true
//data types , premtive data types,
'use strict';
var orderId = 1;
var orderShippingAddress = '84349 Wolf Flat';
var orderShipped = false;
var orderShippingAssigned = undefined;
var orderRating = null;
console.log(typeof orderId);
console.log(typeof orderShippingAddress);
console.log(typeof orderShipped);
console.log(typeof orderShippingAssigned);
console.log(typeof orderRating);
//type conversion
//convert all data types to Number and output in console
//number to number
var integerType = Number(1);
console.log(typeof integerType);
//string to number
//numeric string to number
integerType = Number('1');
console.log(integerType);
console.log(typeof integerType);
//alphanumeric string to number
integerType = Number('1s');
console.log(integerType);
console.log(typeof integerType);
//boolean to number
integerType = Number(true);
console.log(integerType);
console.log("boolean to number ", typeof integerType);
//undefined to number
integerType = Number(undefined);
console.log(integerType);
console.log("typeof undefined is " + typeof integerType);
//null to number
integerType = Number(null);
console.log(integerType);
console.log("typeof null is " + typeof integerType);
// convet all data types to string
console.log("Starting %cstring", "color:blue");
//number to string
var stringType = String(1);
console.log(stringType);
console.log(typeof stringType);
//string to string
stringType = String('1');
console.log(stringType);
console.log(typeof stringType);
//string to string
stringType = String(true);
console.log(stringType);
console.log(typeof stringType);
//undefined to string
stringType = String(undefined);
console.log(stringType);
console.log(typeof stringType);
//null to string
stringType = String(null);
console.log(stringType);
console.log(typeof stringType);
//All data types to boolean
//undefined to string
stringType = String(undefined);
console.log(stringType);
console.log(typeof stringType);
//number to boolean
var booleanType = Boolean(-123232);
console.log(booleanType);
console.log(typeof booleanType);
//string to boolean
booleanType = Boolean('1asa');
console.log(booleanType);
console.log(typeof booleanType);
//undefined to boolean
booleanType = Boolean(undefined);
console.log(booleanType);
console.log(typeof booleanType);
//null to boolean
booleanType = Boolean(null);
console.log(booleanType);
console.log(typeof booleanType);
//concatenation
integerType = 1;
stringType = '21';
booleanType = false;
var newType = integerType + stringType;
console.log("Type is:" + typeof newType);
if (true) {
var numb = Number(newType);
if (!isNaN(numb) && typeof numb === 'number') {
newType = numb + 2;
}
}
console.log("New type " + typeof newType);
</script>
<script id="jsbin-source-javascript" type="text/javascript">//jshint esnext:true
//data types , premtive data types,
let orderId = 1
let orderShippingAddress = '84349 Wolf Flat'
let orderShipped = false
let orderShippingAssigned = undefined
let orderRating = null
console.log(typeof orderId)
console.log(typeof orderShippingAddress)
console.log(typeof orderShipped)
console.log(typeof orderShippingAssigned)
console.log(typeof orderRating)
//type conversion
//convert all data types to Number and output in console
//number to number
let integerType = Number(1)
console.log(typeof integerType)
//string to number
//numeric string to number
integerType = Number('1')
console.log(integerType)
console.log(typeof integerType)
//alphanumeric string to number
integerType = Number('1s')
console.log(integerType)
console.log(typeof integerType)
//boolean to number
integerType = Number(true)
console.log(integerType)
console.log("boolean to number ",typeof integerType)
//undefined to number
integerType = Number(undefined)
console.log(integerType)
console.log("typeof undefined is "+typeof integerType)
//null to number
integerType = Number(null)
console.log(integerType)
console.log("typeof null is "+typeof integerType)
// convet all data types to string
console.log("Starting %cstring","color:blue")
//number to string
let stringType = String(1)
console.log(stringType)
console.log(typeof stringType)
//string to string
stringType = String('1')
console.log(stringType)
console.log(typeof stringType)
//string to string
stringType = String(true)
console.log(stringType)
console.log(typeof stringType)
//undefined to string
stringType = String(undefined)
console.log(stringType)
console.log(typeof stringType)
//null to string
stringType = String(null)
console.log(stringType)
console.log(typeof stringType)
//All data types to boolean
//undefined to string
stringType = String(undefined)
console.log(stringType)
console.log(typeof stringType)
//number to boolean
let booleanType = Boolean(-123232)
console.log(booleanType)
console.log(typeof booleanType)
//string to boolean
booleanType = Boolean('1asa')
console.log(booleanType)
console.log(typeof booleanType)
//undefined to boolean
booleanType = Boolean(undefined)
console.log(booleanType)
console.log(typeof booleanType)
//null to boolean
booleanType = Boolean(null)
console.log(booleanType)
console.log(typeof booleanType)
//concatenation
integerType = 1
stringType = '21'
booleanType = false
let newType = integerType + stringType
console.log("Type is:"+typeof newType)
if(true){
let numb = Number(newType)
if(!isNaN(numb) && typeof numb === 'number')
{
newType = numb + 2
}
}
console.log("New type "+typeof newType)
</script></body>
</html>
//jshint esnext:true
//data types , premtive data types,
'use strict';
var orderId = 1;
var orderShippingAddress = '84349 Wolf Flat';
var orderShipped = false;
var orderShippingAssigned = undefined;
var orderRating = null;
console.log(typeof orderId);
console.log(typeof orderShippingAddress);
console.log(typeof orderShipped);
console.log(typeof orderShippingAssigned);
console.log(typeof orderRating);
//type conversion
//convert all data types to Number and output in console
//number to number
var integerType = Number(1);
console.log(typeof integerType);
//string to number
//numeric string to number
integerType = Number('1');
console.log(integerType);
console.log(typeof integerType);
//alphanumeric string to number
integerType = Number('1s');
console.log(integerType);
console.log(typeof integerType);
//boolean to number
integerType = Number(true);
console.log(integerType);
console.log("boolean to number ", typeof integerType);
//undefined to number
integerType = Number(undefined);
console.log(integerType);
console.log("typeof undefined is " + typeof integerType);
//null to number
integerType = Number(null);
console.log(integerType);
console.log("typeof null is " + typeof integerType);
// convet all data types to string
console.log("Starting %cstring", "color:blue");
//number to string
var stringType = String(1);
console.log(stringType);
console.log(typeof stringType);
//string to string
stringType = String('1');
console.log(stringType);
console.log(typeof stringType);
//string to string
stringType = String(true);
console.log(stringType);
console.log(typeof stringType);
//undefined to string
stringType = String(undefined);
console.log(stringType);
console.log(typeof stringType);
//null to string
stringType = String(null);
console.log(stringType);
console.log(typeof stringType);
//All data types to boolean
//undefined to string
stringType = String(undefined);
console.log(stringType);
console.log(typeof stringType);
//number to boolean
var booleanType = Boolean(-123232);
console.log(booleanType);
console.log(typeof booleanType);
//string to boolean
booleanType = Boolean('1asa');
console.log(booleanType);
console.log(typeof booleanType);
//undefined to boolean
booleanType = Boolean(undefined);
console.log(booleanType);
console.log(typeof booleanType);
//null to boolean
booleanType = Boolean(null);
console.log(booleanType);
console.log(typeof booleanType);
//concatenation
integerType = 1;
stringType = '21';
booleanType = false;
var newType = integerType + stringType;
console.log("Type is:" + typeof newType);
if (true) {
var numb = Number(newType);
if (!isNaN(numb) && typeof numb === 'number') {
newType = numb + 2;
}
}
console.log("New type " + typeof newType);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment