Created
October 31, 2019 11:12
-
-
Save hillbilly300/3f0be139f9063b3e64966b3b0730cf9f to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/kejekuc
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> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
//jshint esnext:true | |
//functions | |
/** | |
1.Factory(Normal) function(preferred for readibility) | |
2.Arrow function | |
3.Function expressions | |
3.1.Anonymouse Function Expression | |
3.2.Named Function Expression(preferred for readibility) | |
3.3.IIFE | |
4.Constructor Function | |
**/ | |
const user = { | |
name:'Waqar Hussain', | |
age:23, | |
male:true | |
} | |
//function | |
function getUserAsArray(){ | |
var userPropertiesArray = [] | |
for (let userProperty in user){ | |
userPropertiesArray.push(user[userProperty]) | |
} | |
return userPropertiesArray | |
} | |
function convertArrayIntoNestedArray(userArr=[]){ | |
return userArr.map(function elToArray(el){ | |
return [el] | |
}) | |
} | |
function printUserObject(){ | |
console.log(user) | |
console.log(convertArrayIntoNestedArray(getUserAsArray())) | |
return user | |
} | |
printUserObject() | |
//arrow function | |
const userAge = user=> user.age | |
console.log(userAge(user)) | |
//function expressions (Fn.Ex) | |
/** | |
1.Anonymous F.E | |
2.Named F.E | |
*/ | |
//anonymous function expression | |
const printUserName = function(userName){ | |
console.log(userName) | |
} | |
printUserName(user.name) | |
//named function expression | |
const printUser = function printUserr(user){ | |
console.log(user) | |
} | |
printUser(user); | |
//IIFE | |
//doesnot pollute global scope | |
//cannot be assingned to a variable, like normal function expression | |
//but , its value can be assigned to a variable | |
//no return value | |
(function(){ | |
console.log('isMale') | |
})(); | |
//return value | |
var result = (function add() { | |
return 2+3 | |
})(); | |
console.log(result); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">//jshint esnext:true | |
//functions | |
/** | |
1.Factory(Normal) function(preferred for readibility) | |
2.Arrow function | |
3.Function expressions | |
3.1.Anonymouse Function Expression | |
3.2.Named Function Expression(preferred for readibility) | |
3.3.IIFE | |
4.Constructor Function | |
**/ | |
const user = { | |
name:'Waqar Hussain', | |
age:23, | |
male:true | |
} | |
//function | |
function getUserAsArray(){ | |
var userPropertiesArray = [] | |
for (let userProperty in user){ | |
userPropertiesArray.push(user[userProperty]) | |
} | |
return userPropertiesArray | |
} | |
function convertArrayIntoNestedArray(userArr=[]){ | |
return userArr.map(function elToArray(el){ | |
return [el] | |
}) | |
} | |
function printUserObject(){ | |
console.log(user) | |
console.log(convertArrayIntoNestedArray(getUserAsArray())) | |
return user | |
} | |
printUserObject() | |
//arrow function | |
const userAge = user=> user.age | |
console.log(userAge(user)) | |
//function expressions (Fn.Ex) | |
/** | |
1.Anonymous F.E | |
2.Named F.E | |
*/ | |
//anonymous function expression | |
const printUserName = function(userName){ | |
console.log(userName) | |
} | |
printUserName(user.name) | |
//named function expression | |
const printUser = function printUserr(user){ | |
console.log(user) | |
} | |
printUser(user); | |
//IIFE | |
//doesnot pollute global scope | |
//cannot be assingned to a variable, like normal function expression | |
//but , its value can be assigned to a variable | |
//no return value | |
(function(){ | |
console.log('isMale') | |
})(); | |
//return value | |
var result = (function add() { | |
return 2+3 | |
})(); | |
console.log(result); | |
</script></body> | |
</html> |
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
//jshint esnext:true | |
//functions | |
/** | |
1.Factory(Normal) function(preferred for readibility) | |
2.Arrow function | |
3.Function expressions | |
3.1.Anonymouse Function Expression | |
3.2.Named Function Expression(preferred for readibility) | |
3.3.IIFE | |
4.Constructor Function | |
**/ | |
const user = { | |
name:'Waqar Hussain', | |
age:23, | |
male:true | |
} | |
//function | |
function getUserAsArray(){ | |
var userPropertiesArray = [] | |
for (let userProperty in user){ | |
userPropertiesArray.push(user[userProperty]) | |
} | |
return userPropertiesArray | |
} | |
function convertArrayIntoNestedArray(userArr=[]){ | |
return userArr.map(function elToArray(el){ | |
return [el] | |
}) | |
} | |
function printUserObject(){ | |
console.log(user) | |
console.log(convertArrayIntoNestedArray(getUserAsArray())) | |
return user | |
} | |
printUserObject() | |
//arrow function | |
const userAge = user=> user.age | |
console.log(userAge(user)) | |
//function expressions (Fn.Ex) | |
/** | |
1.Anonymous F.E | |
2.Named F.E | |
*/ | |
//anonymous function expression | |
const printUserName = function(userName){ | |
console.log(userName) | |
} | |
printUserName(user.name) | |
//named function expression | |
const printUser = function printUserr(user){ | |
console.log(user) | |
} | |
printUser(user); | |
//IIFE | |
//doesnot pollute global scope | |
//cannot be assingned to a variable, like normal function expression | |
//but , its value can be assigned to a variable | |
//no return value | |
(function(){ | |
console.log('isMale') | |
})(); | |
//return value | |
var result = (function add() { | |
return 2+3 | |
})(); | |
console.log(result); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment