Development JavaScript JSON JQuery DOM

Home > Preview

The flashcards below were created by user mateotete on FreezingBlue Flashcards.


  1. What is JavaScript?
    JavaScript is a scripting language that doesn't need to compile its code before being run and which is executed by the browser when a page is downloaded or in response to an event triggered by the user. It is also the most popular programming language in the world and used on everything from web pages, servers, pcs, tablets, cell phones, refrigerators, cars, and more.
  2. What is the DOM?
    Everything in an HTML document exist as a node (ie., {title}, {link}, {a}, text, div) which is displayed by the browser to the user; the DOM is a heirarchial tree of nodes which display each of these objects much like a tree and allow a programmer generic access to these objects, thereby behaving much like a HTML API. The Document Object Model (DOM) allows programmers generic access (ie., adding, deleting, manipulating) to these HTML objects and their attributes and styles. It's language independent, so it can be manipulated in JavaScript, VBScript, Java, and more
  3. Write to the DOM to change the text, font color, and font style of a textbox named txtName
    n = document.getElementById("txtName"); n.innerHTML = "Hello"; n.style.fontSize = "25px"; n.style.color = "#DFDFDF";
  4. What are the two ways of commenting code in JavaScript?
    /* for multiple lines */ and // for single lines
  5. Variable names can use these three types of characters:
    letter, $, or _
  6. What are data types exist in JavaScript?
    string, number, boolean, array, object, null, and undefined
  7. Does JavaScript have dynamic data types? Explain.
    Because data types can be changed on the fly, for example, the following variable will change its data type five times, from undefined, null, string, number, and finally to boolean: var name; name = null; name = "Joe"; name = 30; name = false;
  8. Write two simple JavaScript arrays called cars and populate it.
    var cars = new Array(); cars[0] = "Ford"; cars[1] = "Dodge"; or var cars = new Array("Saab","Volvo","BMW");
  9. Write a simple person object in JavaScript then use it.
    var person={firstname:"John",lastname:"Doe",id:5566}; alert(person.firstname + ' ' + person.lastname);
  10. Write a simple JavaScript function that interprets a JSON object and then uses it.
    var jsonCont = '["Europe", "Asia", "Australia", "Antarctica","North America", "South America", "Africa"]'; var continents = eval( jsonCont );alert(continents[0] + " is one of the " + continents.length + " continents.");
  11. Should you use Eval() or parseJSON() and why?
    The eval function blindly evaluates whatever expression it is passed. An untrustworthy source could therefore include potentially dangerous JavaScript along with or mixed into the literal notation that makes up the JSON data and so it is recommended that you parse the JSON text using the parseJSON() function found in the json.js file, like: var continents = arrayAsJSONText.parseJSON(); The parseJSON() function also uses eval, but only if the string contained in arrayAsJSONText conforms to the JSON text standard. It does this using a clever regular expression test.
  12. What if you want to parse a JSON object, not in the JavaScript on the browser, but in the server-side code in C#?
    Then you could import one of numerous libraries that convert JSON into server-side functions such as the one used with Ajax.
  13. What's the most used JavaScript call?
    document.getElementById()
  14. Write an if statement to check for null or undefined types.
    if (typeof(obj) == null || typeof(obj) == undefined) { /* Do something */ }
  15. What's the difference between null and undefined?
    A variable is undefined if it can't be found or hasn't been initialized, such as var x;. A variable is null if its value has been set to null or its contents cleared.
  16. What is JSON?
    JavaScript Object Notation (JSON) is a language independent, free-text notation mechanism used to describe an object or list of objects, almost identical in functionality to XML but with a different syntax.
  17. Give several string functions commonly used in programming.
    indexOf(), lastIndexOf, match(), replace(), search(), split(), substr(), substring(), toUpperCase(), trim, valueOf()
  18. What is the value of the following call: x = "5" + 3;
    53
  19. Write a basic switch statement with a default value in JavaScript:
    switch(x){case 1: break; case 2: break; default: }
  20. What can you do to set a boolean value to false?
    false, 0, -0, null, undefined, NaN all set a boolean equal to false because anything else is considered true
  21. Write a basic for loop in JavaScript
    for(var i = 0; i { city.length; i++) { document.write(city); }
  22. What can be used to stop execution in a for loop?
    You can use a "break" or "continue" statement in a for loop.
  23. How do you create a local and global JavaScript variable?
    Local variables are declared in a function and may or may not contain the var prefix; however, global variables are those created outside of all functions, thus in the main section of the script.
  24. Write code to send the button name and object to a JavaScript function:
    onClick = "Display(this);". function Display(obj) { var o = obj.name; alert(o); }
  25. What is a callback function?
    A function passed to another function as a parameter.
  26. Write a simple callback function consisting of alerts.
    function mySandwich(param1, param2, callback) { alert('Started eating my sandwich.nnIt has: ' + param1 + ', ' + param2);callback();} mySandwich('ham', 'cheese', function() { alert('Finished eating my sandwich.');});
  27. Write a Person object using JSON notation:
    { "first":"Matt","last":"Johnson","age":25,"address":{"city":"Lancaster","state":"NY"}}
  28. How is a JSON object evaluated in JavaScript and what does that mean?
    One of the most common uses of JSON is to fetch JSON data from a web server, convert the JSON data to a JavaScript object, and then use it on the web pages. This can be done with the following syntax: var obj = eval ("(" + txt + ")"); . However, the eval() function in JavaScript can also be used to execute any JavaScript it receives, thus possess a security risk.
  29. What is JQuery?
    jQuery is a JavaScript framework, which purpose is to make it much easier to use JavaScript on your website. You could also describe jQuery as an abstraction layer, since it takes a lot of the functionality that you would have to write many lines of JavaScript to accomplish and wraps it into functions that you can call with a single line of code.
  30. Navigate the DOM tree to change the third paragraph of a webpage and change it's background color to light grey.
    var parasInDiv = parasDiv.getElementsByTagName("p"); for (var i = 0; i { parasInDiv.length; i++) { if (i == 2) { parasInDiv[i].style.backgroundColor = "lightgrey";}}
  31. Write a simple JQuery function to hide each paragraph on a webpage when clicked.
    $(document).ready(function(){ $("p").click(function(){ $(this).hide() ;});});
  32. What major companies use the JQuery library?
    Microsoft, Netflix, Google, and IBM
  33. JQuery is useful for manipulating what technologies?
    HTML, DOM, CSS, HTML events, AJAX, and provides numerous built-in utilities.
  34. What is the basic syntax of JQuery?
    $(selector).action(); // $ give access to JQuery, selector is the element we are looking for, and action is the JQuery method to perform.
  35. Perform the following four (4) actions of hiding: (a) hide the current element, (b) hide all paragraphs, (c) hide a paragraph with the id "paragraph3", and (d) hide all elements given the class id of "TablePar".
    (a) $(this).hide(); (b) $("p").hide(); (c) $("#paragraph3").hide(); (d) $(".TablePar").hide();
  36. All JQuery functions are in this function. What is the function and why do we do this?
    The reason is because we want to make sure the DOM is fully loaded before calling anything in the DOM, for example, trying to hide an object that hasn't been written to the DOM would generate an error. The function is: $(document).ready(function() { /* all your JQuery code would go here */ });
  37. Write a JQuery function to turn all textbox objects grey/white when in them.
    $("input").focus(function(){$(this).css("background-color","#cccccc");}); $("input").blur(function(){ $(this).css("background-color","#ffffff");});
  38. What is wrong with the following code snippet: $("button").click(function(){ $("p").hide(1000);alert("The paragraph is now hidden");});?
    The alert box will be called before the paragraph has been hidden. This can be fixed by using a JQuery Callback function.
  39. Write a JQuery callback function that hides all paragraphs in a document when any button on the page is clicked, followed by an alert box stating the paragraphs are now hidden.
    $("button").click(function(){$("p").hide("slow",function(){alert("The paragraph is now hidden");});});
  40. Write a JQuery call to get the value of a textbox after clicking a button; After, what would need to be changed in order to get the ID attribute of that same textbox.
    $("#btn1").click(function(){alert("Value: " + $("#test").val());}); /* to get an attribute, simply replace the "val" keyword with the "attr" keyword containing the name of the attribute you'd like, such as: .attr("ID")
  41. Using JQuery, set a paragraph styling to font-size 10px, red, and italicized.
    $("#p").css({"background-color":"red","font-size":"10px", "font-style":"italics"});
  42. Ajax can work closely with JQuery to build post, get, and load Ajax file functions. Write a small JQuery function to load the contents of a file into a div element using AJAX.
    $(document).ready(function(){ $("button").click(function(){$("#div1").load("demo_test.txt");});});
  43. What methods are available for traversing a DOM tree using JQuery?
    Numberous method calls exist, but most popular are .parent(), .children(), .find(), .siblings(), next(), .first(), .last(), and .eq()
  44. What's the difference between window.onload = function() {} and $(document).ready(function() {})?
    Onload waits for the entire page to be loaded, including images and such. The Ready function occurs first, when the DOM has been fully created and is ready to be manipulated but not necessarily when the entire content of the page has been loaded.

Card Set Information

Author:
mateotete
ID:
268219
Filename:
Development JavaScript JSON JQuery DOM
Updated:
2017-08-08 16:58:35
Tags:
Software Development JavaScript JSON JQuery DOM
Folders:
Software Development JavaScript JSON JQuery DOM
Description:
Software Development JavaScript JSON JQuery DOM
Show Answers:

Home > Flashcards > Print Preview