Chapter 9 : JavaScript Part 2 Flashcards
How to declare function?
function name ( parameter1, parameter2, parameter3 )
{
statement;
}
- parameters
-
names listed in the function definition
arguments - real values received by the function when it is invoked
-
names listed in the function definition
What does the argument behaves inside the function?
- Behave as local variables
What does the function will do when it reaches a return statement?
- Stop executing the function and return the value in the return statement
- The return value is returned back to the caller
Write a function which times both parameter p1 and p2 and return the results
<script> function returnProduct (p1, p2) { return p1*p2 } document.getElementById("demo").innerHTML = returnProduct(4,3); </script>
<p><p>
</p></p>
What is the advantages of using JavaScript functions?
- Code Reusability
- Use the same code with different arguments to generate different results
What does the Date objects allows?
- Lets us work with dates ( years, months, days, hours, minutes, seconds and milliseconds )
List out the constructor for creating a date
- new Date()
List out 4 ways for initiating a date
- new Date()
- new Date(milliseconds)
- new Date (dateString)
- new Date (year, month, day, hours, minutes, seconds, mulliseconds )
List out 4 formats for JavaScript date input formats
- ISO Date
- “2015-03-25”
- Short Date
- “03/25/2015”
- Long Date
- “Mar 15 2015”
- “25 Mar 2015”
- Full Date
- “Wednesday March 25 2015”
What date format is used for date record?
- ISO Date
List out 10 date methods
- getDate()
- getDay()
- getFullYear()
- getHours()
- getMiliseconds()
- getMinutes()
- getMonth()
- getSeconds()
- getTime()
What does getDate does?
- Get the day number from 1 to 31
What does getDay does?
- Get the weekday as number from 0 to 6
0 - Monday
1 - Tuesday
.
.
6 - Sunday
What does getFullYear() does?
- Get the four digit year (YYYY)
What does getHours() does?
- Get the hours ( 0 - 23 )
What does getMilliseconds() does?
- Get milliseconds ( 0 - 999 )
What does getMinutes() does?
- Get minutes ( 0 - 59 )
What does getMonth() does?
- Get month ( 0 - 11 )
What does getSeconds() does?
- Get seconds ( 0 - 59 )
What does getTime() does?
- Get time ( Milliseconds since January 1, 1970 )
List out conditional statements for JavaScript ( 2 )
- If Statement
- Switch Statement
How to write if, else if and else statement?
if ( condition1 )
{
statement;
}
else if ( condition2 )
{
statement;
}
else
{
statement;
}
List out the syntax for switch statement
switch ( expression )
{
case n:
statment;
break
case n:
statment;
break
default:
statment;
break
}
List out 4 types of loops
- for
- loops through a block of code a number of times
- for / in
- loops through the properties of an object
- while
- loops through a block of code while a specified condition is true
- 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
What loop is most often to use when we want to create a loop?
for ( statement1 ; statement2 ; statement3 )
{
statement;
}
What is the syntax for while loop?
while ( condition )
{
statement;
}
What is the syntax for do / while loop?
do
{
statement;
}
while ( condition ) ;