100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Exam (elaborations)

CGS 3066 - Exam 2, Javascript Questions and Answers Solved Correctly

Rating
-
Sold
-
Pages
6
Grade
A+
Uploaded on
21-06-2025
Written in
2024/2025

CGS 3066 - Exam 2, Javascript Questions and Answers Solved Correctly How to embed Javascript in HTML - Answers <script> tag <script src=""></script> How Javascript is executed - Answers Script file executed from top to bottom and run by the browser for-loops - Answers for (let i = 0; i < 5; i++) { ... } while-loops - Answers while (notFinished) { ... } Conditionals - Answers If statements if (...) { ... } else { ... } Writing a function - Answers function name( ) { statement; statement; ... } Calling a function - Answers name( ); Variables in Javascript - Answers var, let, const Always use const or let var - Answers Function scope variable, same as let but dated let - Answers Block scope variable const - Answers Block scope constant, can't be reassigned Function scope variable - Answers Only go out of scope at the end of functions so you can refer to the same variable after the block has ended (after the loop or if-statement in which they are declared) Block scope variable - Answers Can only be referred to within block (in the same brackets) Value types of variables - Answers Boolean, number, string, symbol, null, undefined, *object Boolean type variables - Answers True or False, use && (and) || (or) ! (negation) Example. let isTeenager = age > 12 && age < 20; age = 15; isTeenager = true String type variables - Answers Anything in single or double quotes Null type variables - Answers Valu

Show more Read less
Institution
CGS 3066
Course
CGS 3066









Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
CGS 3066
Course
CGS 3066

Document information

Uploaded on
June 21, 2025
Number of pages
6
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

Content preview

CGS 3066 - Exam 2, Javascript Questions and Answers Solved Correctly

How to embed Javascript in HTML - Answers <script> tag

<script src="filename.js"></script>

How Javascript is executed - Answers Script file executed from top to bottom and run by the browser

for-loops - Answers for (let i = 0; i < 5; i++) { ... }

while-loops - Answers while (notFinished) { ... }

Conditionals - Answers If statements

if (...) {

...

} else {

...

}

Writing a function - Answers function name( ) {

statement;

statement;

...

}

Calling a function - Answers name( );

Variables in Javascript - Answers var, let, const

Always use const or let

var - Answers Function scope variable, same as let but dated

let - Answers Block scope variable

const - Answers Block scope constant, can't be reassigned

Function scope variable - Answers Only go out of scope at the end of functions so you can refer to the
same variable after the block has ended (after the loop or if-statement in which they are declared)

Block scope variable - Answers Can only be referred to within block (in the same brackets)

, Value types of variables - Answers Boolean, number, string, symbol, null, undefined, *object

Boolean type variables - Answers True or False, use && (and) || (or) ! (negation)



Example.

let isTeenager = age > 12 && age < 20;

age = 15;

isTeenager = true

String type variables - Answers Anything in single or double quotes

Null type variables - Answers Value meaning "this has no value"

Undefined type variables - Answers The value of a variable with no value assigned

Arrays - Answers Object types used to create lists of data, 0-based indexing, can check size via length
property



Example.

let list = [ ]; //creates empty list

let groceries = ['milk', 'cocoa puffs'];

groceries [1] = 'kix'; //changes cocoa puffs to kix



let first5 = [1,2,3,4,5]

console.log(first5[3]); //prints 4

Event-driven programming - Answers Code doesn't run right away but executes after some event fires
(click, hover, key, etc.)

Event Handler - Answers Any function listening to an event that executes when it occurs

Event Listener - Answers Tells function to run when event occurs



addEventListener(event name, function name);

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
joshuawesonga22 Liberty University
View profile
Follow You need to be logged in order to follow users or courses
Sold
26
Member since
7 months
Number of followers
1
Documents
9766
Last sold
3 hours ago
Tutor Wes

Hi there! I'm Tutor Wes, a dedicated tutor with a passion for sharing knowledge and helping others succeed academically. All my notes are carefully organized, detailed, and easy to understand. Whether you're preparing for exams, catching up on lectures, or looking for clear summaries, you'll find useful study materials here. Let’s succeed together!

3.3

3 reviews

5
1
4
0
3
1
2
1
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions