Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instanceof and typeof #30

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,26 @@
<head>
<title>ES6</title>
<link rel="icon" type="image/png" href="favicon.png" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
crossorigin="anonymous">
</head>

<body>
<br />
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link active" href="#">Main</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contacts</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Register</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Login</a>
</li>
</ul>
<script src="index.js"></script>
</body>

Expand Down
45 changes: 18 additions & 27 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
/*
Modify "personInfo" function to match console.log output at the end of the challenge.
/*typeof return's type is "string". The value is :
1- the underlying primitive type for primitive type operands (string, number, undefined, boolean, etc...)
2- "object" for all reference types
3- "object" for null
4- "function" for functions
*/

Object that is returned by "personInfo" function must contain only shorthand property names.
*/
// console.log(typeof(undefined)) //undefined
// console.log(typeof(null)) //object
// console.log(typeof({})) //object
// console.log(typeof([])) //object not array
// console.log(typeof( ()=>{})) //function not object
// console.log(typeof( function(){})) //function not object
// console.log(typeof( function(){})) //function not object

const personInfo = (/* parameters */) => {
/* return ... */
};
/* Intanceof :
1- always return false for primitive types as they don't have function constructor in the proto list
2- true if the function constructor on the right is in the proto list of the argument

const person = {
name: "Alice",
age: 19,
location: {
country: "England",
city: "London"
}
};

console.log(personInfo(person));
/*
{
name: "Alice",
personAge: 19,
origin: "England",
homeCity: "London",
friendsQty: 0,
recordCreatedAt: *current year*
}
*/

*/
2 changes: 2 additions & 0 deletions tempCodeRunnerFile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var type= typeof []
console.log(type)