




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A compilation of questions and answers related to javascript, covering fundamental concepts such as keywords, data types, variables, operators, constants, expressions, and control structures. It also includes information on language levels, program design, algorithms, and various javascript functions. This resource is designed to help students prepare for exams or quizzes on javascript programming.
Typology: Exams
1 / 8
This page cannot be seen from the preview
Don't miss anything!





Keywords - Correct Answers -Terms in a programming language that are reserved for special purposes by the programming language. The three most common data types are: - Correct Answers -numbers, strings, boolean Variables - Correct Answers -Program data is stored at locations in memory while a program is running. The data value stored in a variable can then be used, and modified, by referencing its name. Names can only contain - Correct Answers -letters, numbers, underscores, and dollar signs.. Names can only begin with - Correct Answers -a letter, underscore, or dollar sign. (generally, they always start with a letter) Can not have the same name as a - Correct Answers -JavaScript keyword Spaces are - Correct Answers -not allowed in variable names Variable names should be - Correct Answers -descriptive of the data they will store. Use camel case for variable names with - Correct Answers -multiple words in the name: Operators - Correct Answers -Operators are used to modify or compare data. An operator is simply a symbol or word that is used to evaluate data in a similar manner as common math. There are 6 types of operators - Correct Answers -Assignment Mathematical (Arithmetic) Comparison Logical Bitwise Special The Direct Assignment Operator (=) - Correct Answers -The Direct Assignment Operator (=) Assignment operators are used to assign a value to a JavaScript variable.
Constants - Correct Answers -A constant is similar to a variable except that the value doesn't change during program execution, it remains constant. A constant is just a variable in JavaScript. Mathematical Operators - Correct Answers -The Mathematical operators are the symbols used to add, subtract, multiply, and divide numbers in JavaScript. Expressions - Correct Answers -Expressions evaluate to values Any piece of code that produces a value is an expression What is a program statement? - Correct Answers -It is an individual instruction for the computer to process the if statement - Correct Answers -A selection control structure evaluates a condition, which is an expression that's true or false. This allows the program to choose between different courses of action. Comparison Operators - Correct Answers -Comparison Operators evaluate two values as equal or different (the same, less-than or greater-than). They operate the same way as relational operators in math. The while loop - Correct Answers -The repetition control structure, a loop, is a code block that is executed one or more times Comments - Correct Answers -// and /* */ The JavaScript Console. It allows developers to: - Correct Answers -Interactively execute JavaScript on a command line. ○ Log JavaScript messages and output that are not visible outside of the console. ○ Troubleshoot, test, and debug code. ○ It is not part of JavaScript. It is provided as part of the JavaScript runtime environment. In our case, the browser. Language Level: Low-Level - Correct Answers -Closest to machine language Language Level: Lower Mid-Level - Correct Answers -Human readable but able to write at the machine level if necessary - slightly more abstracted from the machine level. Memory efficient Programmer still has to code mostly by hand Language Level: Upper Mid-Level - Correct Answers -Human readable - Higher level of abstraction from the machine level Medium memory efficiency
The logical operator || (OR) - Correct Answers -returns true if either or both conditions are true. The logical operator! (NOT) - Correct Answers -returns true if a single condition is FALSE. Variable Scope - Correct Answers -The scope of a variable determines its availability (visibility) to different parts of your program. JavaScript global variables: - Correct Answers -Available to the whole script, or program. Declared at the beginning of the script/program using the var keyword. JavaScript local function variables: - Correct Answers -Only visible to the function they are declared in. Declared at the beginning of the function using the var keyword. What are functions? - Correct Answers -A function is a named collection of programming statements that performs a specific task, a function. To add values to a populated array: - Correct Answers -arrayName[index] = value; color[2] = 'blue'; Array functions: push - Correct Answers -Add one or more values to the end of an array using the push function. The push function returns the new length of the array.
Program execution continues at the line following the function call after the function is finished executing. Anatomy of a Custom function - Correct Answers -A custom function is created with a function declaration using the function keyword. Function declarations should be placed at the beginning of the script. The name of the function follows the function keyword. It must be a unique identifier that follows the same naming rules as variables. Function names should be meaningful. The function name is followed by an optional parameter list enclosed in parentheses. Parameters become local variables within the function, and are only available within the function. Use empty parentheses if there are no parameters. The function body follows the parameter list. It consists of one or more program statements enclosed within curly braces. A function can optionally return a value using the return statement. Only one return value is allowed. A value of undefined is returned by default if there is not an explicit return value. If present, the return statement immediately ends execution of the function. What Is an Array? - Correct Answers -An array is a type of variable that stores a list of values of the same data type To create an empty array in JavaScript use the following syntax: - Correct Answers -var arrayName = [ ]; Ex. var color = [ ]; To add values to the empty array: - Correct Answers -arrayName[index] = value; Ex. color[0] = 'red'; To get the length of an array use the array length property: - Correct Answers - arrayName.length; //returns the # of elements Ex. color.length; To create a populated array in JavaScript use the following syntax: - Correct Answers -var arrayName = [value1, value2, ..., valueN]; var color = [ 'red', 'green']; var integers = [1, 2, 3]; Array functions: Removing elements - Correct Answers -Remove the last element of an array with the pop function. The pop function returns the removed element.
document.write("The current loop iteration is : " + i + '
'); } The array forEach Method - Correct Answers -Provides a way to make JavaScript call a given function for every element in the array The forEach method iterates over the array, passing each element in turn as an argument to the function specified in parentheses The array forEach method passes three arguments to the specified function: The current element The index of the element The whole array The array forEach method - Correct Answers -A function must be defined before using it in the array forEach method var words = ['variable', 'function', 'scope', 'loop', 'condition']; function displayElements(value){ document.write(value); } words.forEach(displayElements); What is an Object? - Correct Answers -An object allows us to declare one variable that is able to store one or more pieces of related data. Objects provide a way to group and organize this data in a way that more closely resembles its real world model and use. Objects also provide a way to associate functionality (behavior) directly to the data within the object. Objects collect related data and functions together Parts of an Object: - Correct Answers -Like an array, an object has a name:
To create an empty Object in JavaScript use the following syntax: - Correct Answers -var ObjectName = { }; //Object literal syntax Ex. var student = { }; To add values to the empty Object: - Correct Answers -Use dot notation ObjectName.property = value; Ex. student.name = 'Jill'; Ex. student.email =" [email protected]"; Creating an Object Literal - Correct Answers -An object initialized with properties and values when the object is created is called an object literal. An object literal is a comma-separated list of property name and property value pairs enclosed within curly braces. The property name and value are separated by a colon. To create object literal in JavaScript use the following syntax: - Correct Answers -var ObjectName = { property: value, property: value }; Creating an Object Literal - Correct Answers -var student = { name: value, major: value }; →Adding values to an initialized Object is the same as adding values to an empty object: ObjectName.property = value; student.email = '[email protected]'; Deleting object properties - Correct Answers -delete employee.email; ObjectName = { }; or ObjectName = null;