1/113
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
JavaScript
A dynamic computer programming language.
It is lightweight and most used as a part of web pages; whose implementations allow client-side script to interact with the user and make dynamic pages.
It is an interpreted programming language with object-oriented capabilities.
LiveScript,
Netscape,
Netscape 2.0,
1995
JavaScript was first known as _____, but _____ changed its name to JavaScript, possibly because of the excitement being generated by Java
Made its first appearance in _____ in _____ with this name.
Brendan Eich,
Netscape Communications Corporation,
Mocha,
LiveScript
JavaScript was originally developed by _____ of _____ under the name _____, then _____, and finally renamed to JavaScript.
Client-side JavaScript
the most common form of the language.
The script should be included in or referenced by an HTML document for the code to be interpreted by the browser.
It means that a web page need not be a static HTML, but can include programs that interact with the user, control the browser, and dynamically create HTML content.
JavaScript client-side mechanism
provides many advantages over traditional CGI server-side scripts.
For example, you might use JavaScript to check if the user has entered a valid e-mail address in a form field.
JavaScript code
Is executed when the user submits the form, and only if all the entries are valid, they would be submitted to the Web Server
JavaScript
can be used to trap user-initiated events such as button clicks, link navigation, and other actions that the user initiates explicitly or implicitly.
Less server interaction,
Immediate feedback to the visitors,
Increased interactivity,
Richer interfaces
4 Advantages of JavaScript
Less server interaction
You can validate user input before sending the page off to the server.
This saves server traffic, which means less load on your server.
Immediate feedback to the visitors
They do not have to wait for a page reload to see if they have forgotten to enter something.
Increased interactivity
You can create interfaces that react when the user hovers over them with a mouse or activates them via the keyboard
Richer interfaces
You can use JavaScript to include such items as drag-and-drop components and sliders to give a _____ to your site visitors.
full-fledged programming language
Limitations of JavaScript
We cannot treat JavaScript as a _____.
Client-side JavaScript
does not allow the reading or writing of files.
This has been kept for security reason.
networking applications
JavaScript cannot be used for _____ because there is no such support available.
multithreading, multiprocessor
JavaScript does not have any _____ or _____ capabilities
<script> </script>
JavaScript can be implemented using JavaScript statements that are placed within the _____ HTML tags in a web page.
<head>
You can place the <script> tags, containing your JavaScript, anywhere within your web page, but it is normally recommended that you should keep it within the _____ tags
<script> tag
alerts the browser program to start interpreting all the text between these tags as a script
Language,
Type
The script tag takes two important attributes
Language
This attribute specifies what scripting language you are using.
Although recent versions of HTML (and XHTML, its successor) have phased out the use of this attribute.
javascript
Typically, Language value will be _____.
Type
This attribute is what is now recommended to indicate the scripting language in use
text/javascript
Type value should be set to _____
spaces,
tabs,
newlines
JavaScript ignores these 3 that appear in JavaScript programs
You can use them freely in your program and you are free to format and indent your programs in a neat and consistent way that makes the code easy to read and understand
Simple Statements in JavaScript
are generally followed by a semicolon character, just as they are in C, C++, and Java
separate line
JavaScript, however, allows you to omit this semicolon if each of your statements are placed on a _____.
semicolons
It is a good programming practice to use _____.
case-sensitive language
JavaScript is a _____.
This means that the language keywords, variables, function names, and any other identifiers must always be typed with a consistent capitalization of letters
C,
C++
JavaScript supports both _____-style and _____-style comments.
//,
end of a line
Any text between a _____ and the ____ is treated as a comment and is ignored by JavaScript.
/* and */
Any text between the characters _____ is treated as a comment.
This may span multiple lines.
<!--
JavaScript also recognizes the HTML comment opening sequence _____.
JavaScript treats this as a single-line comment, just as it does the // comment.
//-->
The HTML comment closing sequence --> is not recognized by JavaScript so it should be written as _____.
modern browsers
All the _____ come with built-in support for JavaScript.
Frequently, you may need to enable or disable this support manually.
Internet Explorer
Here are the steps to turn on or turn off JavaScript in _____:
Follow Tools -> Internet Options from the menu.
Select Security tab from the dialog box.
Click the Custom Level button.
Scroll down till you find the Scripting option.
Select Enable radio button under Active scripting.
Finally click OK and come out.
To disable JavaScript support in your _____, you need to select Disable radio button under Active scripting.
Firefox
Here are the steps to turn on or turn off JavaScript in _____:
Open a new tab -> type about:config in the address bar.
Then you will find the warning dialog. Select I will be careful, I promise!
Then you will find the list of configure options in the browser.
In the search bar, type JavaScript.enabled.
There you will find the option to enable or disable JavaScript by right-clicking on the value of that option -> select toggle.
If JavaScript.enabled is true, it converts to false upon clicking toggle. If JavaScript is disabled, it gets enabled upon clicking toggle.
Chrome
Here are the steps to turn on or turn off JavaScript in _____:
Click the Chrome menu at the top right-hand corner of your browser.
Select Settings.
Click Show advanced settings at the end of the page.
Under the Privacy section, click the Content settings button.
In the “JavaScript” section, select “Do not allow any site to run JavaScript” or “Allow all sites to run JavaScript (recommended)”
Opera
Here are the steps to turn on or turn off JavaScript in _____:
Follow Tools → Preferences from the menu.
Select Advanced option from the dialog box.
Select Content from the listed items.
Select Enable JavaScript checkbox.
Finally click OK and come out.
To disable JavaScript support in _____, you should not select the Enable JavaScript checkbox.
<head>,
<body>,
<head> and <body>,
external file
There is a flexibility given to include JavaScript code anywhere in an HTML document
However, the most preferred ways to include JavaScript in an HTML file are as follows:
Script in _____ section.
Script in _____ section.
Script in both _____ and _____ sections.
Script in an _____ and then include it in the <head>...</head> section.
<head>
If you have a small piece of JavaScript code that you want to execute when a page loads, it is a good idea to keep that code in the _____ section of your HTML document.
<body>
If you need a script to run as the page loads so that the script generates content in the page, then the script goes in the _____ portion of the document.
external file
As you begin to work more extensively with JavaScript, you will be likely to find that there are cases where you are reusing identical JavaScript code on multiple pages of a site.
You are not restricted to maintaining identical code in multiple HTML files.
The <script> tag provides a mechanism to allow you to store JavaScript in an _____ and then include it into your HTML files.
To use JavaScript from an _____, you need to write all your JavaScript source code in a simple text file with the extension .js and then include that file.
Event
JavaScript’s interaction with HTML is handled through _____ that occur when the user or the browser manipulates a page.
When the user clicks a button, that click too is an event.
Other examples include events like pressing any key, closing a window, resizing a window, etc.
Developers can use these to execute JavaScript coded responses, which cause buttons to close windows, messages to be displayed to users, data to be validated, and virtually any other type of response imaginable.
Onclick Event Type
This is the most frequently used event type which occurs when a user clicks the left button of his mouse.
You can put your validation, warning etc., against this event type.
onsubmit
an event that occurs when you try to submit a form.
You can put your form validation against this event type.
Onmouseover and onmouseout
These two event types will help you create nice effects with images or even with text as well.
onmouseover
triggers when you bring your mouse over any element
onmouseout
triggers when you move your mouse out from that element.
Page Redirection
a situation where you clicked a URL to reach a page X but internally you were directed to another page Y.
window.location.href
Adds the current page to the session history, allowing the user to go back
location.replace
Replaces the current page without adding it to history; the user cannot go back.
location.reload()
method used to refresh a web page
This code can be called automatically upon an event or simply when the user clicks on a link.
setTimeout()
is a built-in JavaScript function which can be used to execute another function after a given time interval
dialog boxes
can be used to raise an alert, to get confirmation on any input, or to have some kind of input from the users
Alert Dialog Box
Mostly used to give a warning message to the users.
Alert box
gives only one button “OK” to select and proceed.
Confirmation Dialog Box
Mostly used to take user’s consent on any option.
It displays a dialog box with two buttons: OK and Cancel.
If the user clicks on the OK button, the window method confirm() will return true.
If the user clicks on the Cancel button, then confirm() returns false.
Prompt Dialog Box
is very useful when you want to pop up a text box to get user input.
Thus, it enables you to interact with the user.
The user needs to fill in the field and then click OK.
This dialog box has two buttons: OK and Cancel.
If the user clicks the OK button, the window method prompt() will return the entered value from the text box.
If the user clicks the Cancel button, the window method prompt() returns null
prompt()
The prompt dialog box is displayed using a method called _____ which takes two parameters:
a label which you want to display in the text box and
a default string to display in the text box.
JavaScript Datatypes
These are the type of values that can be represented and manipulated in a programming language.
numbers,
strings of text,
boolean
Primitive data types (3)
null,
undefined
trivial data types (2)
each of which defines only a single value.
object
JavaScript supports a composite data type known as ______
integer,
floating-point
Java does not make a distinction between _____ values and _____ values.
floating-point
All numbers in JavaScript are represented as ______values.
64-bit floating-point format,
IEEE 754 standard
JavaScript represents numbers using the ______ defined by the _____.
Variables
can be thought of as named containers
var
Variables are declared with the _____ keyword
Use the _____ keyword only for declaration or initialization, once for the life of any variable name in a document.
variable initialization
Storing a value in a variable
can be done at the time of variable creation or at a later point in time when you need that variable.
You should not re-declare the same variable twice.
untyped language
JavaScript is an _____.
This means that a JavaScript variable can hold a value of any data type.
Unlike many other languages, you do not have to tell JavaScript during variable declaration what type of value the variable will hold.
The value type of a variable can change during the execution of a program and JavaScript takes care of it automatically.
scope of a variable
is the region of your program in which it is defined.
Global Variables
Has global scope which means it can be defined anywhere in your JavaScript code
Local Variables
Will be visible only within a function where it is defined.
Function parameters are always local to that function.
local,
global
Within the body of a function, a ______ variable takes precedence over a _____ variable with the same name.
global
If you declare a local variable or function parameter with the same name as a global variable, you effectively hide the _____ variable.
variable name
You should not use any of the JavaScript reserved keywords as a _____.
should not start with a numeral.
They must begin with a letter or an underscore character.
are case-sensitive.
operands,
operator
Take a simple expression 4 + 5 is equal to 9.
Here 4 and 5 are called _____ and ‘+’ is called the _____.
arithmetic operators
addition,
subtraction,
multiplication,
division,
modulus,
increment,
decrement
addition (+)
adds two operands
works for numeric as well as string (concatenation)
subtraction (-)
subtracts the second operand from the first
multiplication (*)
multiply both operands
division (/)
divide the numerator by the denominator
modulus (%)
outputs the remainder of an integer division
increment (++)
increases an integer value by one
decrement (—)
decreases an integer value by one
comparison operator
equal,
not equal,
greater than,
less than,
less than or equal to
equal (==)
checks if the value of two operands are equal or not, if yes, then the condition becomes true
not equal (!=)
checks if the value of two operands are equal or not, if the values are not equal, then the condition becomes true
greater than (>)
checks if the value of the left operand is greater than the value of the right operand, if yes, then the condition becomes true
less than (<)
checks if the value of the left operand is less than the value of the right operand, if yes, then the condition becomes true
greater than or equal to (>=)
checks if the value of the left operand is greater than or equal to the value of the right operand, if yes, then the condition becomes true
less than or equal to (<=)
checks if the value of the left operand is less than or equal to the value of the right operand, if yes, then the condition becomes true
logical operators
logical AND (&&),
logical OR (||),
logical NOT (!)
logical AND (&&)
if both the operands are non-zero, then the condition becomes true
logical OR (||)
if any of the two operands are non-zero, then the condition becomes true
logical NOT (!)
reverses the logical state of its operand
bitwise operators
AND (&),
OR (|),
XOR (^),
NOT (~),
Zero fill left shift (<<),
signed right shift (>>),
zero fill right shift (>>>)
AND (&)
Sets each bit to 1 if both bits are 1
OR (|)
Sets each bit to 1 if one of two bits is 1