Podcast Beta
Questions and Answers
Which of the following are considered front-end languages?
What does URL stand for?
Uniform Resource Locator
A domain name is a unique name for a web site.
True
Which of these is NOT a method for HTTP requests?
Signup and view all the answers
The protocol used for secured communication over the web is called ______.
Signup and view all the answers
Which HTML tag is used to define headings?
Signup and view all the answers
What is the purpose of the alt attribute in an image tag?
Signup and view all the answers
Which of the following best describes what JavaScript is?
Signup and view all the answers
Match the following HTML elements with their descriptions:
Signup and view all the answers
What is the purpose of using comments in JavaScript?
Signup and view all the answers
The language in which JavaScript is primarily written is called ______.
Signup and view all the answers
JavaScript is case sensitive.
Signup and view all the answers
What does the following JavaScript statement do? document.getElementById("demo").innerHTML = "Hi, Everyone."
Signup and view all the answers
Semicolons in JavaScript are optional at the end of statements.
Signup and view all the answers
Which of the following characters can be used to start a JavaScript variable name?
Signup and view all the answers
What does the assignment operator =
do in JavaScript?
Signup and view all the answers
What happens if you declare a variable without assigning a value?
Signup and view all the answers
What is the significance of the function
keyword in JavaScript?
Signup and view all the answers
How are JavaScript strings written?
Signup and view all the answers
The length of a string is found in the property ______.
Signup and view all the answers
Which of the following is a correct way to define a JavaScript variable?
Signup and view all the answers
JavaScript variables are case sensitive.
Signup and view all the answers
What does the new
keyword do when defining a string in JavaScript?
Signup and view all the answers
What do arrays use for indexes?
Signup and view all the answers
What do objects use for indexes?
Signup and view all the answers
When should you use objects?
Signup and view all the answers
Which of the following is a bad way to create an array?
Signup and view all the answers
How can you check if a variable is an array?
Signup and view all the answers
The pop()
method removes the last element from an _____.
Signup and view all the answers
What does the push()
method do?
Signup and view all the answers
What method would you use to sort an array alphabetically?
Signup and view all the answers
What does the reverse()
method do?
Signup and view all the answers
What is returned if you compare two equal values using ===
?
Signup and view all the answers
When is the splice()
method used?
Signup and view all the answers
What is the maximum number of decimal places in JavaScript?
Signup and view all the answers
The result of 0.2 + 0.1
in JavaScript is approximately ______.
Signup and view all the answers
What will the value of y
be after executing var y = 9999999999999999;
?
Signup and view all the answers
Division by zero in JavaScript results in NaN.
Signup and view all the answers
Which function is used to check if a value is NaN in JavaScript?
Signup and view all the answers
What keyword is used to create a number object in JavaScript?
Signup and view all the answers
What does typeof Infinity
return?
Signup and view all the answers
What are the three JavaScript functions used for converting variables to numbers?
Signup and view all the answers
Which Math method rounds a number to the nearest integer?
Signup and view all the answers
JavaScript arrays can hold different types of elements.
Signup and view all the answers
Which method can be used to get the length of an array?
Signup and view all the answers
The ISO date format in JavaScript is represented as ______.
Signup and view all the answers
What method converts a date to a UTC string in JavaScript?
Signup and view all the answers
How do you create a new date object for January 1, 1970?
Signup and view all the answers
What does the getFullYear()
method do?
Signup and view all the answers
JavaScript supports associative arrays.
Signup and view all the answers
Study Notes
Front End Languages
- HTML, CSS, and JavaScript are the “front end languages” that are used to build web pages and applications.
Front End Development
- Front end development is not design.
- It is the process of creating HTML, CSS, and JavaScript for a user interface, based on designs from designers.
URL
- URL stands for Uniform Resource Locator.
- It is the address of a resource on the internet.
- It includes the protocol, domain name, and file or resource name.
- Dynamic URLs include additional parameters in a key=value pair format that can be used to provide unique content or to pass information between client and server.
- URL encoding is used to convert non-ASCII characters into a valid ASCII format using a percent sign followed by two hexadecimal digits.
HTTP
- HTTP stands for Hypertext Transfer Protocol.
- It is a protocol used to communicate between a client and server over the web.
- Two common methods for requests are
GET
andPOST
. -
GET
requests data from a resource and has limited length. -
POST
submits data to be processed to a resource and has no data limit.
HTTPS
- HTTPS is Hypertext Transfer Protocol Secure.
- It is a secure version of HTTP where all communication is encrypted and authenticated using SSL.
Web Server
- A web server is a program that serves files that form web pages to users in response to their requests.
Application Server
- An application server is a software framework that allows the creation and running of web applications.
Web Services
- Web services are applications that communicate over the web using HTTP and communicate using XML messages.
Web Agents / User Agents
- These are software applications used by users to communicate with the web server, such as web browsers.
Domain
- A domain name is a unique name for a website, such as google.com or facebook.com.
- The domain name is mapped to an IP address, which represents a physical location on the internet.
- A domain name consists of a Top Level Domain (TLD), Second Level Domain, and optionally a Third Level Domain or subdomain.
Hosting
- Internet hosting services run internet servers that allow organizations and individuals to serve content on the web.
FTP
- FTP stands for File Transfer Protocol.
- It is a standard network protocol used to transfer files between hosts over a TCP-based network.
- Files are split into small data packets and transmitted over an authenticated connection.
FTP Client
- An FTP client is software that allows users to communicate with an FTP server to transfer files.
HTML
- HTML stands for Hyper Text Markup Language.
- It is the standard markup language used to create web pages.
- Web browsers can read HTML files and render them into visible or audible web pages.
HTML Documents
- HTML documents must start with a type declaration:
<!DOCTYPE html>
. - The document itself begins with
<html>
and ends with</html>
. - The visible part of the HTML document is between
<body>
and</body>
.
HTML Headings
- HTML headings are defined with
<h1>
to<h6>
tags.
HTML Paragraphs
- HTML paragraphs are defined with
<p>
tag.
HTML Images
- HTML images are defined with the
<img>
tag. - The
src
attribute specifies the source file,alt
specifies alternative text, andwidth
andheight
specify the size.
HTML Elements
- HTML elements are written with a start tag, end tag, and content in between.
- All HTML documents consist of nested HTML elements.
HTML Attributes
- HTML elements can have attributes that provide additional information about the element.
- Attributes are specified in the start tag and are in name/value pairs.
Lang Attribute
- The
lang
attribute in the<html>
tag declares the document language, which is important for accessibility and search engines.
Title Attribute
- The
title
attribute provides a short description of the element or content.
Href Attribute
- The
href
attribute is used in the<a>
tag to define the target URL or destination of the link.
Alt Attribute
- The
alt
attribute is used with the<img>
tag to provide alternative text for images that cannot be displayed. - Screen readers use the
alt
text to describe images to users.
Image Size: Width and Height
- You can use the
width
andheight
attributes in the<img>
tag to define the dimensions of an image.
JavaScript Programs
- JavaScript programs are a series of instructions executed by the computer.
- In JavaScript, these instructions are called statements and are separated by semicolons.
JavaScript Statements
- Statements are composed of values, operators, expressions, keywords, and comments.
- JavaScript ignores spaces and line breaks, but uses semicolons to separate statements.
JavaScript Values
- JavaScript has two types of values:
- literals: fixed values such as numbers or strings.
- variables: values that can be changed.
JavaScript Literals
- Numbers are written with or without decimals.
- Strings are text written within double or single quotes.
JavaScript Variables
- Variables are used to store data values.
- The
var
keyword is used to define variables. - Values are assigned to variables using an equal sign.
JavaScript Operators
- The assignment operator (=) assigns values to variables.
- Arithmetic operators (+ , - , * , /) are used to perform calculations.
JavaScript Keywords
- Keywords identify actions to be performed.
- The
var
keyword creates a new variable.
JavaScript Comments
- Comments are used to explain code and make it more readable.
- Single-line comments start with
//
. - Multi-line comments start with
/*
and end with*/
.
JavaScript Case Sensitivity
- JavaScript identifiers are case-sensitive, so
lastName
andlastname
are different variables.
JavaScript Character Set
- JavaScript uses the Unicode character set, which covers all the characters, punctuations, and symbols in the world.
JavaScript Code Blocks
- JavaScript statements can be grouped together in code blocks, which are enclosed in curly brackets (
{...}
). - Code blocks are used to define statements that are executed together.
Comments
- Using comments to prevent execution of code is beneficial for code testing
- The
//
symbol in front of a code line turns it into a comment, preventing execution
JavaScript Variables
- JavaScript variables are used to store data values.
- In the example:
var x = 5;
,x
holds the value5
. - Identifiers are unique names given to variables, following these rules:
- Can contain letters, digits, underscores, and dollar signs
- Must start with a letter or $ and _
- Case sensitive (y and Y are different variables)
- Cannot use reserved words (JavaScript keywords) as names
-
=
(equal sign) is an assignment operator, not an "equal to" operator in JavaScript. - JavaScript variables can hold numbers (like 100) and text values (called strings, like "John Doe").
- Strings are written inside double or single quotes. Numbers are written without quotes.
- Declaring a variable in JavaScript is called "declaring."
- Use the
var
keyword followed by the variable name to declare a variable:var carName;
- Assign a value to a declared variable using the equal sign:
carName = "Volvo";
- Multiple variables can be declared in one statement:
var person = "John Doe", carName = "Volvo", price = 200;
- Variables declared without a value will have the value
undefined
:var carName;
- Re-declaring a JavaScript variable will not remove its value.
JavaScript Operators
- Arithmetic operations can be performed with JavaScript variables using operators like = and +.
- The
+
operator is also used to concatenate (add) strings. - Adding a number and a string returns a string.
JavaScript Functions
- A JavaScript function is a block of code designed to perform a specific task.
- Functions are invoked (executed) when "something" calls them.
- Function syntax:
function name(parameter1, parameter2, parameter3) { code to be executed }
- Parameters are listed in the function definition. Arguments are the actual values passed when invoking the function.
- Functions can be called by:
- Events (e.g., user clicks a button)
- JavaScript code (e.g., calling the function directly)
- Automatically (self-invoked)
- The
return
statement stops function execution and returns a value to the invoking statement. - Functions are important as they allow code reuse and flexibility.
- Invoking a function uses the () operator:
toCelsius(32)
- Accessing a function without () returns the function definition:
toCelsius
- Functions can be used as variables, like:
var text = "The temperature is " + toCelsius(32) + " Centigrade";
JavaScript Objects
- JavaScript objects are containers for named values called properties and methods.
- Properties can be primitive values, other objects, or functions.
- An object method is an object property containing a function definition.
JavaScript Scope
- Scope determines the accessibility of variables, objects, and functions.
- JavaScript has function scope: The scope changes within functions.
- Local variables (declared within a function) are only accessible inside that function.
- Global variables (declared outside a function) are accessible from anywhere on the webpage.
- Assigning a value to an undeclared variable automatically makes it global.
- The lifetime of a variable:
- Local variables are deleted when the function ends.
- Global variables are deleted when the page closes.
- Function arguments act as local variables inside functions.
- In HTML, the global scope belongs to the
window
object.
JavaScript Events
- Events are actions triggered by the user or browser (e.g., page loading, input field change, button click).
- JavaScript can execute code when these events occur.
- HTML elements can have event handler attributes (e.g.,
onclick
) with JavaScript code.
JavaScript Strings
- A JavaScript string is a sequence of characters (like "Mike Slough").
- Strings can be enclosed in single or double quotes.
- Quotes can be used inside a string as long as they don't match the surrounding quotes.
-
length
is a built-in property to determine the string's length. - Escape character (
\
) is used to include special characters in strings:var y = "We are the so-called \"Vikings\" from the north.“
- Break up long code lines after operators or use string addition for readability.
- Strings can be primitive values or objects (created with
new String
).-
==
(equality operator) considers strings with equal values as equal. -
===
(strict equality operator) requires both the type and value to be equal.
-
- Strings have properties and methods, even primitive values.
JavaScript Numbers
- JavaScript numbers can be written with or without decimals.
- Extra large or small numbers can be represented using scientific notation (exponent).
- JavaScript numbers are always 64-bit floating-point numbers, based on the IEEE 754 standard.
- Integer values are typically accurate up to 15 digits.
- Floating-point arithmetic might have slight inaccuracies due to the format.
- Hexadecimal numbers are written with
0x
prefix:var x = 0xFF;
-
Infinity
is returned for calculations exceeding the maximum number or division by 0.- Type of Infinity is
number
.
- Type of Infinity is
-
NaN
(Not a Number) represents invalid arithmetic operations.- Use
isNaN()
function to check if a value is NaN.
- Use
- Numbers can be primitive values or objects (
new Number()
).-
==
considers numbers with equal values as equal. -
===
requires both type and value equality.
-
- Numbers have properties and methods even though they are primitive values.
JavaScript Number Methods
- JavaScript number methods are used to manipulate and transform numbers.
- They return new values without affecting the original variable.
- Some examples:
-
toString()
: Returns a number as a string. -
toExponential()
: Rounds a number and returns it in exponential notation. -
toFixed()
: Rounds and returns a string with a specified number of decimals. -
toPrecision()
: Returns a string with a specified number of digits (including decimals). -
valueOf()
: Returns a number as a number.
-
Converting Variables to Numbers
- These three global JavaScript methods can convert variables to numbers:
-
Number()
: Converts variables to numbers. -
parseInt()
: Converts a string to an integer. -
parseFloat()
: Converts a string to a floating-point number.
-
Number
- The
Number()
function converts a value to a number. -
true
converts to1
. -
false
converts to0
. -
new Date()
converts to a timestamp representing milliseconds since January 1, 1970. -
"10"
converts to10
but"10 20"
returnsNaN
(Not a Number).
parseInt()
- Parses a string and returns an integer.
- Spaces are allowed within the string.
- Only returns the first number encountered.
- Returns
NaN
it cannot be converted to an integer. -
parseInt("10")
returns 10 -
parseInt("10.33")
returns 10 -
parseInt("10 20 30")
returns 10 -
parseInt("10 years")
returns 10 -
parseInt("years 10")
returnsNaN
parseFloat()
- Parses a string and returns a number.
- Spaces are allowed within the string.
- Only returns the first number encountered.
- Returns
NaN
if it cannot be converted to a number. -
parseFloat("10")
returns 10 -
parseFloat("10.33")
returns 10.33 -
parseFloat("10 20 30")
returns 10 -
parseFloat("10 years")
returns 10 -
parseFloat("years 10")
returnsNaN
Math Object
- The Math object contains useful mathematical methods and constants.
-
Math.random()
returns a random number between 0 and 1. -
Math.min()
andMath.max()
find the minimum or maximum values from a list of arguments.
Math Object Methods
-
Math.round()
rounds a number to the nearest integer. -
Math.ceil()
rounds a number up to the nearest integer. -
Math.floor()
rounds a number down to the nearest integer.
Math Object Constants
-
Math.E
returns Euler's number. -
Math.PI
returns PI. -
Math.SQRT2
returns the square root of 2. -
Math.SQRT1_2
returns the square root of 1/2. -
Math.LN2
returns the natural logarithm of 2. -
Math.LN10
returns the natural logarithm of 10. -
Math.LOG2E
returns base 2 logarithm of E. -
Math.LOG10E
returns base 10 logarithm of E.
Date Object
- The Date object is used to work with dates.
- Dates can be represented as strings or numbers.
- A Date object represented as a number is the number of milliseconds since January 1, 1970, 00:00:00.
Displaying Dates
- You can display a date using
Date()
within ainnerHTML
statement.
Creating Date Objects
- You can create a Date object using the
new Date()
constructor. -
new Date()
creates a Date object representing the current date and time. -
new Date(milliseconds)
creates a Date object based on a timestamp (milliseconds since January 1, 1970). -
new Date(dateString)
creates a Date object based on a valid date string. -
new Date(year, month, day, hours, minutes, seconds, milliseconds)
creates a Date object with the specified date and time.
Date Methods
-
toString()
returns a string representation of a Date object. -
toUTCString()
returns a UTC string representation of a Date object. -
toDateString()
returns a more readable string representation of a Date object.
Date Formats
- There are three main date formats:
- ISO Dates: YYYY-MM-DD
- Long Dates: MMM DD YYYY (month can be written fully or abbreviated)
- Short Dates: MM/DD/YYYY or MM-DD-YYYY
Date Get Methods
-
getDate()
returns the day of the month (1-31). -
getDay()
returns the day of the week (0-6). -
getFullYear()
returns the four-digit year. -
getHours()
returns the hour (0-23). -
getMilliseconds()
returns the milliseconds (0-999). -
getMinutes()
returns the minutes (0-59).
Date Set Methods
-
setDate()
sets the day of the month. -
setFullYear()
sets the year (optionally the month and day). -
setHours()
sets the hour. -
setMilliseconds()
sets the milliseconds.
Adding Days to a Date
- You can add days to a Date object using
setDate(getDate() + days)
.
Converting a String to a Date
-
Date.parse()
converts a valid date string to milliseconds since January 1, 1970. - You can create a Date object using the milliseconds returned by
Date.parse()
.
Comparing Dates
- You can compare Date objects using standard comparison operators (
>
,<
,>=
,<=
).
Arrays
- An array is a special variable that can hold multiple values.
- Array elements are accessed using index numbers (starting from 0).
Creating Arrays
- You can create an array using an array literal:
-
var arrayName = [item1, item2, ...]
.
-
- You can also create an array using the
new Array()
constructor.
Accessing Array elements
- You access array elements by their index number.
Array Properties and Methods
-
length
property: Returns the number of elements in the array. -
sort()
method: Sorts array elements alphabetically. -
reverse()
method: Reverses the order of elements in an array.
Adding Array Elements
- Use
fruits[fruits.length] = "Lemon";
to add an element at the end. -
push()
method adds an element at the end of the array.
Removing Array Elements
-
pop()
method removes the last element from the array. -
shift()
method removes the first element from the array.
Changing Array Elements
- You can change an element by assigning a new value to the index.
Deleting Array Elements
- Use
delete
operator.
Splicing an Array
-
splice()
method allows adding or removing elements at a specific index.
Array Methods for String Conversion
-
valueOf()
returns a comma separated string representation of the array. -
toString()
returns the same asvalueOf()
.
Sorting Arrays using the Compare Function
-
sort()
method can use a compare function to specify a custom sorting order. - The compare function should return a negative, zero, or positive value, based on the comparison of two elements.
- The sort method uses the compare function's return value to determine the sorting order.
Associative Arrays
- JavaScript does not support associative arrays (arrays with named indexes).
Differences Between Arrays and Objects
- Arrays use numbered indexes.
- Objects use named indexes.
- You should use objects where the element names are strings (text).
- You should use arrays where the element names are numbers.
Good Practices for Arrays
- Use the array literal
[]
to create arrays instead ofnew Array()
. - Use the built-in
isArray()
function to check if a variable is an array.
Array Methods
-
pop()
method removes the last element from an array. -
push()
method adds a new element to the end of an array. -
shift()
removes the first element from an array. -
splice()
method removes or adds elements at a specific index. -
sort()
method sorts the elements of an array alphabetically. -
reverse()
method reverses the order of elements in an array. - The
sort()
method can use a compare function to define a custom sorting order.
JavaScript Functions
- When calculating the difference between 40 and 100, the function returns a negative value of -60
- The sort function prioritizes lower values, so 40 will be sorted before 100
- Joining arrays is done by combining two arrays
- The concat() method joins arrays
- For example:
- myGirls array contains "Aisha" and "Meryam"
- myBoys array contains "Bilal", "Umer", and "Ali"
- myChildren array is created using the myGirls.concat(myBoys) method
Slicing Arrays
- The slice() method extracts a portion of an array, creating a new array
- For example:
- the fruits array contains "Banana", "Orange", "Lemon", "Apple", and "Mango"
- the citrus array is created with the fruits.slice(1, 3) method and contains "Orange" and "Lemon", indicating extraction from the first to the third element
- the citrus array is created with the fruits.slice(2) method and contains "Lemon", "Apple", and "Mango", indicating extraction from the second element to the end
JavaScript Comparisons
- Comparison operators are used to determine if variables or values are equal or different
- The operators are used within logical statements
- Example of comparison operators and results for x=5:
- == operator checks for equality. Returns true if both sides are equal, false otherwise.
- === operator checks for equality in both value and type. Returns true if both sides are equal in both, false otherwise.
- != operator checks for inequality, returns true if both sides are not equal, false otherwise.
- !== operator checks for inequality in either value or type, returns true if both sides are not equal, false otherwise.
-
operator checks if the left side is greater than the right side, returns true if it is, false otherwise.
- < operator checks if the left side is less than the right side, returns true if it is, false otherwise.
-
= operator checks if the left side is greater than or equal to the right side, returns true if it is, false otherwise.
- <= operator checks if the left side is less than or equal to the right side, returns true if it is, false otherwise.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
Test your knowledge on front-end languages, HTML, and JavaScript essentials. This quiz covers basic concepts such as HTML tags, HTTP requests, and the purpose of various attributes. Perfect for beginners looking to solidify their understanding of web development fundamentals.