Module #4: Principles of Development Flashcards
(49 cards)
What is jQuery and how do you enable it in your script
jQuery is a JavaScript Library.
We load the jQuery library by adding this line of code in the head
section of our HTML page:
< script src=”https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js” ></ script >
write the basic syntax of jQuery.
$(selector).action()
what is the html() method for?
Give writing syntax and reading syntax example.
To read or write the text inside the tag, use the jQuery html()
method (A method is an action you can do like adding or deleting an HTML element).
< p id=”tag1” >I am a paragraph</p >
var x = $(“#tag1”) .html(); //reading
$(“#tag1”). mhtml(“hello world”); //writing
now the p display hello world
what is the val() method for?
Give writing syntax and reading syntax example.
To read or write the value of the tag, use the jQuery val() method.
< input id=”tag2” type= “text” value=”Old text” >
var x = $(“#tag2”). val(); // Reading
$(“#tag2”). val(“New text”); // Writing
Click event fonction. Understand and give the basic syntax
basic: $(). click();
example:
$(“#btn_1”).click( function(){
//something happens here
console. log( “button click!”);
});
Note: this function has no name. For that reason, it is called an anonymous function.
What is AND, OR, NOT conditions in Javascript?
&& : AND Returns a true value if both expressions are true. This operator only evaluates the second expression if necessary.
||: OR Returns a true value if either expression is true. This operator only evaluates the second expression if necessary.
! NOT Reverses the value of the Boolean expression.
The order of precedence for the logical operators. (AND, OR, NOT)
- NOT operator
- AND operator
- OR operator
what is an array
Array is nothing but a collection of elements: the element can be in the format of a string, number,
Boolean, or even an array.
note: number 0 is assigned to first element of the array
find lenght of an array?
console. log(var of the array.length)
sort an array from a to z
var of the array. sort()
how do you iterate through an array. give me the formula.
var shoppinglist = (penis, graine, fesse)
for (let i = 0 ; i < shoppinglist.length; i++) {console.log(shoppinglist[i] ; }
what is the order output in an array
when using vararray.sort()
number, letter, boulian
Q: What is the role of JavaScript in web development?
–General-purpose language
–Used to manipulate HTML & CSS in the browser in response to events
–Interacts with HTML & CSS but can be studied separately
Q: What is the purpose of the developer console and how do you access it?
–Used to view output from JavaScript (e.g., console. log())
–Helps debug and inspect web pages
–Access in Chrome:
–Click the 3-dot icon (top-right)
–Go to More Tools → Developer Tools
–Select the Console tab
where and how to use JS in HTML?
what is the purpuse of use stric?
console.log() utility?
console.clear() utility?
with what must end a statement?
name me 2 type of data and explain them?
JavaScript is written inside < script> tags
–”use strict”; enforces variable declarations for cleaner code
–console.log() outputs messages to the developer console
–console.clear() clears the console
–Statements end with ;
–JavaScript supports different data types like strings (“hello”) and numbers (10)
Q: How do you write comments in JavaScript?
–Single-line: start with //
–Example: // This is a comment
–Multi-line: start with /* and end with /
–Example:
/ This is a multi-line comment */
Q: How do you create and use variables in JavaScript?
–Create with var (used in this course) or let
–Example: var x; or let y;
–Assign value: x = 5;
–Use in expressions: let z = x + y;
Q: What are the main arithmetic operators in JavaScript?
–Addition:
–Subtraction:
–Multiplication:
–Exponentiation:
–Division:
–Remainder (modulus):
Q: What are the main arithmetic operators in JavaScript?
–Addition: a + b
–Subtraction: a - b
–Multiplication: a * b
–Exponentiation: a ** b
–Division: a / b
–Remainder (modulus): a % b → returns the remainder (e.g., 13 % 5 = 3)
Q: How does order of precedence affect JavaScript expressions?
–Without parentheses: 10 + a / b → division happens first (implicit order)
–With parentheses:
–10 + (a / b) → forces division before addition
–(10 + a) / b → forces addition before division
–Different parentheses = different results due to operator precedence
Q: How does JavaScript handle strings and the + operator? (string concatenation)
–Strings can use single or double quotes: ‘Fred’ or “Velma”
–+ is used for concatenation (joining strings)
–Example: ‘Shaggy’ + ‘Scooby’ → ‘ShaggyScooby’
–+ in JavaScript works for both math and string concatenation
Q: What are the 4 ways to declare variables in JavaScript?
–Automatically (not recommended)
–Using var (used in this course)
–Using let (added in 2015)
–Using const (added in 2015)
–var was used from 1995–2015, mostly for older browsers
Q: What are the rules for naming variables (identifiers) in JavaScript?
–Can include letters, numbers, _, and $
–Cannot start with a number
–Case-sensitive (name ≠ Name)
–Can be any length
–Cannot use reserved words (e.g., var, console)
–Avoid global properties/methods as names
–Examples: subtotal, index_1, taxRate, $log
Q: What are camel case and underscore notation in JavaScript? general rules to write var
–Camel case: no spaces, capitalize each new word → theCat, theDog
–Underscore notation: use _ to separate words → the_cat, the_dog
–Both styles are acceptable — just stay consistent!
Q: What do .length, parseInt(), and .toFixed() do in JavaScript?
–string.length: returns number of characters in a string
→ “Shaggy”.length → 6
–parseInt(string): converts a string to an integer
→ parseInt(‘1812’) → 1812
→ parseInt(‘Elephant’) → NaN (not a number)
–number.toFixed(n): formats a number to n decimal places, returns a string
→ 3.14159.toFixed(2) → “3.14”