Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
Learning JavaScript
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MohammadAli Keshavarz
Learning JavaScript
Commits
a94fbb77
Commit
a94fbb77
authored
5 years ago
by
MohammadAli Keshavarz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Arrays
parent
f82d6479
master
No related merge requests found
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
2 deletions
+30
-2
script.js
script.js
+30
-2
No files found.
script.js
View file @
a94fbb77
...
...
@@ -251,10 +251,9 @@ yearsUntilRetirement(1969, 'Jane');
/*****************************
* Function Statements and Expressions
*/
/*
// Function declaration
// function whatDoYouDo(job, firstName) {}
// Function expression
var whatDoYouDo = function(job, firstName) {
switch(job) {
...
...
@@ -271,4 +270,33 @@ var whatDoYouDo = function(job, firstName) {
console.log(whatDoYouDo('teacher', 'John'));
console.log(whatDoYouDo('designer', 'Jane'));
console.log(whatDoYouDo('retired', 'Mark'));
*/
/*****************************
* Arrays
*/
// Initialize new array
var
names
=
[
'John'
,
'Mark'
,
'Jane'
];
var
years
=
new
Array
(
1990
,
1969
,
1948
);
console
.
log
(
names
[
2
]);
console
.
log
(
names
.
length
);
// Mutate array data
names
[
1
]
=
'Ben'
;
names
[
names
.
length
]
=
'Mary'
;
console
.
log
(
names
);
// Different data types
var
john
=
[
'John'
,
'Smith'
,
1990
,
'designer'
,
false
];
john
.
push
(
'blue'
);
john
.
unshift
(
'Mr.'
);
console
.
log
(
john
);
john
.
pop
();
john
.
pop
();
john
.
shift
();
console
.
log
(
john
);
console
.
log
(
john
.
indexOf
(
23
));
var
isDesigner
=
john
.
indexOf
(
'designer'
)
===
-
1
?
'John is NOT a designer'
:
'John IS a designer'
;
console
.
log
(
isDesigner
);
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment