1/50
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
Inline JavaScript
You can directly add JavaScript within an HTML element’s attribute, such as the onclick attribute of a button.
Internal JavaScript
JavaScript can be written inside a <script> tag within the HTML file’s <head> or <body> section.
It is generally placed in the <head> section for scripts that don’t affect page load,
but if the script manipulates the DOM, it’s usually placed before the closing </body> tag.
external javascript
For modularity and better management, JavaScript code is usually placed in a separate file with the .js extension and linked to the HTML file using the <script> tag
src
If the script is external, you must use the _____ attribute to specify the file path.
defer attribute
ensures the script is executed after the HTML document has been fully parsed
async attribute
runs the script as soon as it is available but without blocking the page from rendering.
Document Object Manipulation (DOM)
represents the structure of a webpage, allowing JavaScript to access and modify the HTML.
It's a tree-like model where every element is a node, and JavaScript interacts with it to change, add, or remove elements dynamically.
Properties
allow you to retrieve or set the value of an element's attributes or characteristics
Methods
are functions associated with objects that can perform actions on elements
getElementById()
returns the element having the given id value
getElementsByName()
returns all the elements having the given name value.
getElementsByTagName()
returns all the elements having the given tag name.
getElementsByClassName()
returns all the elements having the given class name.
document.getElementById()
Returns the element of specified id.
document.getElementByClassName()
Used for selecting or getting the elements through their class name value.
document.getElementsByTagName()
returns all the element of specified tag name.
innerHTML
property can be used to write the dynamic html on the html document
innerText
property can be used to write the dynamic text on the html document.
Here, text will not be interpreted as html text but a normal text
querySelector
The _______________ method in JavaScript is used to select HTML elements using CSS selectors.
It returns the first element within the document that matches the specified selector or group of selectors
querySelectorAll
For selecting multiple elements.
JavaScript events
are actions or occurrences that happen in the browser, which can be detected and handled by JavaScript code.
It can be triggered by user interactions, browser actions, or other actions within the web page.
Event
The change in the state of an object
represents that some activity is performed by the user or by the browser
Event Handling,
Event Handlers
When JavaScript code is included in HTML, js react over these events and allow the execution.
This process of reacting over the events is called _____.
Thus, js handles the HTML events via _____.
addEventListener method
is used to attach an event handler to a specific element.
It allows you to specify the type of event you want to listen for (like a click, keypress, or mouse movement) and the function that should be executed when that event occurs.
useCapture
A boolean that indicates whether to use event capturing (true) or event bubbling (false).
click
mouse event that is triggered when an element is clicked
dblclick
mouse event that is triggered when an element is double-clicked
mouseover
mouse event that is triggered when the mouse pointer enters an element.
mouseout
mouse event that is triggered when the mouse pointer leaves an element.
mousemove
mouse event that is triggered when the mouse is moved over an element.
function
is a group of reusable code which can be called anywhere in your program.
This eliminates the need of writing the same code again and again.
modular codes
function helps programmers in writing _____.
function,
unique function name,
parameters,
statement block
The most common way to define a function in JavaScript is by using the _____keyword,
followed by a _____,
a list of _____(that might be empty),
and a _____ surrounded by curly braces.
comma
A function can take multiple parameters separated by _____.
return
A JavaScript function can have an optional _____ statement.
This is required if you want to return a value from a function.
should be the last statement in a function.
window.print()
The JavaScript print function _____ prints the current web page when executed.
Although it serves the purpose of getting a printout, it is not a recommended way.
printer friendly page
a page with text, no images, graphics, or advertising.
can be made in the following ways:
Make a copy of the page and leave out unwanted text and graphics, then link to that printer friendly page from the original.
If you do not want to keep an extra copy of a page, then you can mark your printable text using proper comments like <!-- PRINT STARTS HERE -->..... <!-- PRINT ENDS HERE --> and then you can use PERL or any other script in the background to purge printable text and display for final printing
switch
The objective of a _____ statement is to give an expression to evaluate and several different statements to execute based on the value of the expression.
The interpreter checks each case against the value of the expression until a match is found.
default
If nothing matches in a switch case, a _____ condition will be used.
break
The __________ statements indicate the end of a particular case.
If they were omitted, the interpreter would continue executing each statement in each of the following cases.
while loop
The most basic loop in JavaScript
Its purpose is to execute a statement or code block repeatedly if an expression is true.
Once the expression becomes false, the loop terminates.
do...while
is like the while loop except that the condition check happens at the end of the loop.
This means that the loop will always be executed at least once, even if the condition is false.
for loop
is the most compact form of looping
loop initialization
where we initialize our counter to a starting value.
initialization statement
is executed before the loop begins.
test statement
will test if a given condition is true or not.
If the condition is true, then the code given inside the loop will be executed, otherwise the control will come out of the loop.
iteration statement
where you can increase or decrease your counter.
for...in loop
used to loop through an object's properties
variablename
In each iteration in a for…in loop, one property from object is assigned to _____ and this loop continues till all the properties of the object are exhausted.
break
is used to exit a loop early, breaking out of the enclosing curly braces.
continue
The _______________ statement tells the interpreter to immediately start the next iteration of the loop and skip the remaining code block