







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
JAVASCRIPT Exam Questions and Answers Latest Graded A+
Typology: Exams
1 / 13
This page cannot be seen from the preview
Don't miss anything!








What must a variable begin with? - ✔✔A letter, $ or _ What is a variable? - ✔✔Container for a piece of data Are variables case sensitive? - ✔✔Yes How do you declare variables? - ✔✔using the var keyword - eg. var myName="Monica"; What will an undeclared variable return? - ✔✔Undefined Two types of variable scope? - ✔✔Local and Global What are the properties of a Local Scope? - ✔✔Within a function, only available within function What are the properties of Global Scope? - ✔✔Outside a function, available to any code outside that function (also within). What is Variable "Hoisting"? - ✔✔Variables are hoisted to the top of the function/statement. It is useful because you can refer to variables declared later in the code. What is best practice regarding variable declarations? - ✔✔Put variable declarations as close to the top of the scope as possible. Prototype Based - ✔✔Each object has a prototype that it inherits properties and abilities from Dynamic Typing - ✔✔Dynamic if the type of variable is interpreted at runtime. First Class Function - ✔✔Treats functions as first class citizens - you can do with functions everything you can do with other elements.
Multi Paradigm Language - ✔✔Supports more than one programming paradigm - developers can work with a variety of styles within javascript. DOM - ✔✔Document Object model. What is DOM? - ✔✔Representation of HTML Page.... What are the two ways to add JS to your site? - ✔✔Internally and Externally. How do you add JS To your site internally? - ✔✔Internally using html tag. Best practice to place it before closing body tag. How do you add JS to your site externally? - ✔✔Add by externally linking to .js files. Is JS case sensitive? - ✔✔Yes JS Statement - ✔✔A command that tells the browser what to do. document.write("hello world"); var myName="lorna"; Can a statement be grouped into useable blocks called functions? - ✔✔Yes. Datatypes - ✔✔Numbers, Strings, Boolean, Arrays, Objects. What are the 2 types of Numbers within Datatypes? - ✔✔Integer: Whole Number (-1, 450) Float:Decimal Point (0.1, 12.454)
Conditionals - ✔✔Statements that allow for code to be executed against conditionals IF, ELSE statements Example of Conditional IF Statement - ✔✔if (This condition is true) {Do this thing} var Country = "Australia"; var Hemisphere, var Language; if (country = "England") { hemisphere = "northern"; language = "english"; } Example of Conditional ELSE Statement - ✔✔Else statements allow us to make an alternative statement if original condition is false if (this condition is true){ ...do this thing }else{ ...do this other thing } Loops - ✔✔Repetitive Conditional statements. Used to perform a calculation a number of times, or to iterate over a set of variables. Three main types of Loops - ✔✔For: Set Number of Iterations While: Certain conditions are met
Do...While: Certain condition is met For Loop Example - ✔✔Repeats until a specific condition becomes false While Loop Example - ✔✔Iterate while the condition is true while (condition) { do this thing } Do While Loop - ✔✔Iterate while the condition is true do { ... this thing } while(condition); Function - ✔✔Re-useable blocks of instructions that can be executed by name.
tags to the content in quotes after x.innerHTML Hello JavaScript! What does this piece of code tell the computer to do? x=document.getElementById("demo") - ✔✔Find the Element ("demo"); document.getElementById("some id") (The "Id" could be anything else.) What does this piece of code tell the computer to do? x.innerHTML="Hello JavaScript!"; - ✔✔Change the content of the x variable to Hello JavaScript! parseInt: If the first character cannot be converted to a number, what is returned? - ✔✔NaN What does parseFloat do? - ✔✔It parses its argument, and returns a floating point number. If it encounters a character other than a sign (+ or - ), numeral (0-9), a decimal point, or an exponent, it returns the value up to that point and ignores that character and all succeeding characters. Leading and trailing spaces are allowed. Math.random() - ✔✔This function returns a floating-point, pseudo-random number in the range 0 to 1 — that is, from 0 (inclusive) up to but not including 1 (exclusive) — which you can then scale to your desired range. The implementation selects the initial seed to the random number generation algorithm; it cannot be chosen or reset by the user. What is the DOM? - ✔✔The DOM is a representation of a webpage that JavaScript can use. Object Prototype - ✔✔function Person(first, last, age, eyecolor) {
.innerHTML - ✔✔can read and alter the elements on a webpage return - ✔✔ends function execution and specifies a value to be returned to the function caller ternary - ✔✔this.items = items !== undefined? items : []; (if items is undefined, return items; otherwise return the array)
// jQuery // $.each(toys, function(index, value){ // console.log(value); // });
tags is changed per what is typed into input box What is a dataset? - ✔✔The dataset property on the HTMLElement interface provides read/write access to all the custom data attributes (data-*) set on the element. This access is available both in HTML and within the DOM. It is a map of DOMString, one entry for each custom data attribute. Math.floor() - ✔✔A function that returns the largest integer less than or equal to a given number. parseFloat() - ✔✔This function parses a string and returns a floating point number. This function determines if the first character in the specified string is a number. If it is, it parses the string until it reaches the end of the number, and returns the number as a number, not as a string. parseInt() - ✔✔This function parses a string and returns an integer. (Only the first number gets returned.) Node properties to navigate between nodes with JavaScript - ✔✔parentNode, childNodes[nodenumber], firstChild, lastChild, nextSibling, previousSibling A common error in DOM processing - ✔✔to expect an element node to contain text