Discussion :  SOU CS Classes The fastest message board... ever.
Forum for discussion, questions, and replies relating to Web Development I 
Goto Thread: PreviousNext
Goto: Forum ListMessage ListNew TopicSearchLog In
Week 7 - Wednesday Discussion
Posted by: harveyd (IP Logged)
Date: November 08, 2007 04:14PM

1. What is a JavaScript function?
2. How are functions useful?
3. What is the difference between a function and a method?
4. Find an article you like that discusses creating functions in JavaScript.
5. JavaScript and other scripting languages are loosely typed. Java is strongly typed. Find an article that describes this concept.
6. What is a function parameter? What is a function argument? What is the difference?
7. How are the braces '{' and '}' used with functions?
8. What do the paseFloat and parseInt method do? Why are they necessary?
9. Tell us something about a method that the browser makes available that we didn't discuss in class.
10. What does the term expression mean in the context of programming languages?
11. Tell us something about the order of operations in JavaScript.
12. What does the keyword, 'null' mean?
13. What is a local variable? What is a global variable?
14. What is the difference between var x = "10" and var x=10?
15. Tell us something about the Firebug JavaScript debugger.
16. Explain how to get what a user typed into a text field. Assume its input tag has an id value of 'myText.'
17. How do you refer to an object for an html tag with its name attribute set to 'myTag?'
18. How do you refer to an object for an html tag with its id attribute set to 'myTag?'
19. What does the term precedence mean in JavaScript? Give an example.
20. What does the JavaScript return statement do? Give an example when this can be useful.
21. What does '++x' mean in JavaScript? How does it differ from 'x++'.
22. What is a difference between a function and a method?
23. Find an article that discusses the tradeoffs between using local and global variables.
24. What are disadvantages of using JavaScript alert and prompt methods?
25. How can alert statements help with debugging your scripts?

Re: Week 7 - Wednesday Discussion
Posted by: (IP Logged)
Date: November 09, 2007 02:51AM

6. What is a function parameter? What is a function argument? What is the difference?

Function parameter: name a function gives a variable
Function argument: name of data passed to a function

The difference is we might want to use the function more than once and we might want to call a function using constants.

Re: Week 7 - Wednesday Discussion
Posted by: (IP Logged)
Date: November 09, 2007 04:27AM

3. What is the difference between a function and a method?

A function is a set of instructions called by name.

A method is an action operating on an object.

Note from dan: the action is also a set of instructions



Edited 2 time(s). Last edit at 11/09/2007 04:29PM by harveyd.

Re: Week 7 - Wednesday Discussion
Posted by: (IP Logged)
Date: November 09, 2007 04:32AM

11. Tell us something about the order of operations in JavaScript.

Javascript starts at the beginning of the page and executes each JavaScript as it comes to it.

Note from dan: this question might have been unclear. It refers to an expression. For example 3+2*6 will execute the multipy first.



Edited 1 time(s). Last edit at 11/09/2007 04:31PM by harveyd.

Re: Week 7 - Wednesday Discussion
Posted by: (IP Logged)
Date: November 09, 2007 04:34AM

16. Explain how to get what a user typed into a text field. Assume its input tag has an id value of 'myText.'

document.getElementById(myText).value

Re: Week 7 - Wednesday Discussion
Posted by: (IP Logged)
Date: November 13, 2007 01:56AM

19. What does the term precedence mean in JavaScript? Give an example.

precedence is how Javascript determines which operator to evaluate first.

13. What is a local variable? What is a global variable?

a local variable is a variable that is given local scope. Such variables are accessible only from the function or block in which it is declared. Local variables are contrasted with global variables.Local variables are special because in most languages they are automatic variables stored on the call stack directly. This means that when a recursive function calls itself, local variables in each instance of the function are given separate memory address space. Hence variables of this scope can be declared, written to, and read, without any risk of side-effects to processes outside of the block in which they are declared.

a global variable is a variable that is accessible in every scope. Interaction mechanism with global variables are called global environment mechanisms. The global environment paradigm is contrasted with the local environment paradigm, where all variables are local with no shared memory.They are usually considered bad practice precisely because of their nonlocality: a global variable can potentially be modified from anywhere, and any part of the program may depend on it. A global variable therefore has an unlimited potential for creating mutual dependencies, and adding mutual dependencies increases complexity. See Action at a distance. However, in a few cases, global variables can be suitable for use. For example, they can be used to avoid having to pass frequently-used variables continuously throughout several functions.

Re: Week 7 - Wednesday Discussion
Posted by: (IP Logged)
Date: November 17, 2007 12:58AM

20. What does the JavaScript return statement do? Give an example when this can be useful.
The return statement causes afunction to return a value. This can save time coding. consider:
function randomChoice (maxValue) {
//Return a random number up to maxValue
var randomValue = Math.floor(Math.random()*maxValue);
return randomvalue;
}
You never have to worry about the Math functions again, just call the randomChoice function and process the resutls.

21. What does '++x' mean in JavaScript? How does it differ from 'x++'.
Both expressions increment the value of x however, they do it at different time. The leading ++ calls for pre-processing which means that the increment happens before anything else while a training ++ means that the increment happens after anything else. These distinctions only matter on the specified line of code; the next line of code will use an incremented value of x regardless of pre or post processing.

24. What are disadvantages of using JavaScript alert and prompt methods?
The alert and prompt methods suspend operation of the browser until the user responds. This can get annoying fast because you can't just ignore the dialog box. This also causes problems when the browser should be usable otherwise. The user might not want anything to do with the web page after that!

Re: Week 7 - Wednesday Discussion
Posted by: (IP Logged)
Date: November 20, 2007 04:41AM

1. Functions are a way of organizing and controlling different sequences of code which work together with other functions. A function typically contains a set of commands for a specific purpose which you want to run at a certain time.

Note from Dan: A function is a block of instructions that is called by name.

2. Functions are useful for a number of reasons. First of all, functions allow the programmer to be able to create practically anything imaginable within their own website. Secondly, functions will also only deploy when called, so once functions are written, they can be used wherever you want to use it--functions are not page specific and can be ran on multiple pages on multiple websites as long as you have the correct call to function listed.

12. null means that there is no value attached. To null out a field is to leave it blank.

14. var x = "10" is a string, whereas var x = 10 is a number.

22. A method must be used within an object whereas a function can be created separately.



Edited 1 time(s). Last edit at 11/20/2007 05:16PM by harveyd.

Re: Week 7 - Wednesday Discussion
Posted by: (IP Logged)
Date: November 27, 2007 02:40PM

3. What is the difference between a function and a method? A method is in an object, a function is not.
6. What is a function parameter? Name a function gives variable.What is a function argument? Name of data passed to a function. What is the difference? We might want to use the function more than once, we might want to call the function using it's constants.

Note from Dan: A parameter is the name a function gives an argument. An argument could be a variable, but it is more accurate to say that it is an expression.



Edited 1 time(s). Last edit at 11/27/2007 04:09PM by harveyd.

Re: Week 7 - Wednesday Discussion
Posted by: (IP Logged)
Date: December 03, 2007 05:39AM

14. What is the difference between var x = "10" and var x=10?
x="10" is a string and x=10 is a value given to x



Sorry, only registered users may post in this forum.
This forum powered by Phorum.