Chapter 9 : JavaScript Part 2 Flashcards

1
Q

How to declare function?

A

function name ( parameter1, parameter2, parameter3 )
{
statement;
}

  • parameters
    • names listed in the function definition
      arguments
    • real values received by the function when it is invoked
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does the argument behaves inside the function?

A
  1. Behave as local variables
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does the function will do when it reaches a return statement?

A
  1. Stop executing the function and return the value in the return statement
  • The return value is returned back to the caller
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Write a function which times both parameter p1 and p2 and return the results

A
<script>
function returnProduct (p1, p2)
{
     return p1*p2
}

document.getElementById("demo").innerHTML = returnProduct(4,3);
</script>

<p><p>
</p></p>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the advantages of using JavaScript functions?

A
  1. Code Reusability
  2. Use the same code with different arguments to generate different results
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does the Date objects allows?

A
  1. Lets us work with dates ( years, months, days, hours, minutes, seconds and milliseconds )
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

List out the constructor for creating a date

A
  1. new Date()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

List out 4 ways for initiating a date

A
  1. new Date()
  2. new Date(milliseconds)
  3. new Date (dateString)
  4. new Date (year, month, day, hours, minutes, seconds, mulliseconds )
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

List out 4 formats for JavaScript date input formats

A
  1. ISO Date
    • “2015-03-25”
  2. Short Date
    • “03/25/2015”
  3. Long Date
    • “Mar 15 2015”
    • “25 Mar 2015”
  4. Full Date
    • “Wednesday March 25 2015”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What date format is used for date record?

A
  1. ISO Date
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

List out 10 date methods

A
  1. getDate()
  2. getDay()
  3. getFullYear()
  4. getHours()
  5. getMiliseconds()
  6. getMinutes()
  7. getMonth()
  8. getSeconds()
  9. getTime()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does getDate does?

A
  1. Get the day number from 1 to 31
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does getDay does?

A
  1. Get the weekday as number from 0 to 6

0 - Monday
1 - Tuesday
.
.
6 - Sunday

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does getFullYear() does?

A
  1. Get the four digit year (YYYY)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does getHours() does?

A
  1. Get the hours ( 0 - 23 )
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does getMilliseconds() does?

A
  1. Get milliseconds ( 0 - 999 )
17
Q

What does getMinutes() does?

A
  1. Get minutes ( 0 - 59 )
18
Q

What does getMonth() does?

A
  1. Get month ( 0 - 11 )
19
Q

What does getSeconds() does?

A
  1. Get seconds ( 0 - 59 )
20
Q

What does getTime() does?

A
  1. Get time ( Milliseconds since January 1, 1970 )
21
Q

List out conditional statements for JavaScript ( 2 )

A
  1. If Statement
  2. Switch Statement
22
Q

How to write if, else if and else statement?

A

if ( condition1 )
{
statement;
}
else if ( condition2 )
{
statement;
}
else
{
statement;
}

23
Q

List out the syntax for switch statement

A

switch ( expression )
{
case n:
statment;
break
case n:
statment;
break
default:
statment;
break
}

24
Q

List out 4 types of loops

A
  1. for
    • loops through a block of code a number of times
  2. for / in
    • loops through the properties of an object
  3. while
    • loops through a block of code while a specified condition is true
  4. do/while
    • loops through a block of code once ( in the do section ) before checking the condition, if the condition is true , then it will repeat the loop again
25
Q

What loop is most often to use when we want to create a loop?

A

for ( statement1 ; statement2 ; statement3 )
{
statement;
}

26
Q

What is the syntax for while loop?

A

while ( condition )
{
statement;
}

27
Q

What is the syntax for do / while loop?

A

do
{
statement;
}
while ( condition ) ;