Keywords variables function names can consist of any

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: mes of Variables and Functions JavaScript is case-sensitive. Example: the if keyword must not be typed as If. keywords, variables, function names CAN consist of any letter, digit, and underscore (_). CANNOT start with a digit. Example: 9To5 is NOT valid. CANNOT be a JavaScript keyword. Examples: b re a k case c o ntinue d e fa ult d e le te do function if im p o rt in ne w else null e xp o rt fa ls e fo r return s witc h th is true These typ e o f var void wh ile with Should be descriptive. Bad examples: Function1, temp names can't tell what the functions do. Function names are generally composed of more than one word: first one is a verb. A common way: First word starts with lowercase, others start with uppercase. Examples: calculateAverage, showRecordDetails (CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong camelCase 4. Program Structure III - 4 Names of Variables and Functions Using the same variable name locally in 2 or more functions is Okay. DON'T create global variables just because of "saving local variables" The uses of such a variable become difficult to track ( bad coding style, create bugs easily ) <s c rip t typ e =" te xt/ja va s c rip t" > func tio n c o nve rtT o G ra d e (m a rk) { &lt...
View Full Document

This note was uploaded on 03/10/2012 for the course CS 1301 taught by Professor Dr.wong during the Winter '08 term at City University of Hong Kong.

Ask a homework question - tutors are online