Chapter 8 : Introduction to JavaScript Flashcards

1
Q

Who invented JavaScript?

A
  1. Brendan Eich ( 1995 )
  • Java
    • General Purpose Programming Language
      JavaScript
    • Used on websites to make them animated and interactive
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

List out 5 examples that JavaScript can do?

A
  1. Change HTML content
  2. Change HTML attributes
  3. Change HTML styles ( CSS )
  4. Hide HTML elements
  5. Show HTML elements
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What HTML tag is used for JavaScript , CSS?

A
  1. <script>
    
    </script>
  2. <style>
    </style>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

When does the JavaScript function called?

A
  1. Executed when the JavaScript function called
  • A function can be called when an event occurs, like when the user clicks a button
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the file extension for JavaScript files?

A
  1. .js
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to link external JavaScript ?

A

  • Can be placed inside < head > or < body >
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the advantages of JavaScript? ( 3 )

A
  1. Separates HTML and code
  2. Makes HTML and JavaScript easier to read and maintain
  3. Cached JavaScript files can speed up page loads
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to add several script files?

A

<scri[t src=”myScript1.js”>
</script>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

List out 4 ways that JavaScript can display data

A
  1. window.alert() - Alert Box
  2. document.write() - Write into HTML Output
  3. innerHTML - Write into HTML element
  4. console.log() - Write into Browser Console
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to show window alert of 5 + 6 ?

A

<!DOCTYPE html>

<html>
<body>

<script>
window.alert(5+6);
</script>

</body>
</html>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How to use document.write() to show 5 + 6 ?

A

<!DOCTYPE html>

<html>
<body>
<button>Try It</button>
</body>
</html>

  • Write the answer 11 where the code is placed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How to display new paragraph for 5 + 6 using JavaScript?

A

<!DOCTYPE html>

<html>
<body>
<p></p>

<script>
**document.getElementById("demo").innerHTML = "<h2>5 + 6</h2>";**
</script>

</body>
</html>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How to write the total amount for 5 + 6 into browser console?

A

<!DOCTYPE html>

<html>
<body>

<script>
console.log(5+6)
          <script>
     </body>
</html>
</script>
</body></html>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is JavaScript Syntax?

A
  1. JavaScript syntax is the set of rules of how JavaScript programs are constructed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

List out 5 statements that JavaScript are composed of

A
  1. Values
  2. Operators
  3. Expressions
  4. Keywords
  5. Comments
  • Statements are being executed one by one, in the same order as they are written
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are program instructions called?

A
  1. Statements
17
Q

What is JavaScript statement seperated by?

A
  1. Semicolons
18
Q

List out JavaScript Arithmetic Operators ( 7 )

A
  1. /
  2. %
  3. ++
19
Q

List out JavaScript assignment operator ( 6 )

A
  1. =
  2. +=
  3. -=
  4. *= ( x = x * y )
  5. /=
  6. %=
20
Q

List out JavaScript Comparison Operators ( 9 )

A
  1. ==
  2. === ( Equal value and equal type )
  3. !=
  4. !== ( Not equal value and not equal type )
  5. >
  6. <
  7. > =
  8. <=
  9. ?
21
Q

List out 2 JavaScript Type Operators

A
  1. typeof
    • Returns the type of a variable
  2. instanceof
    • Returns true if an object is an instance of an object type
22
Q

What are JavaScript comments being used to? ( 2 )

A
  1. Explain JavaScript code, and to make it more readable
  2. Prevent execution, when testing alternative code
23
Q

List out :
1. Single Line Comments
2. Multiline Comments

A
  1. //
  2. Starts with /* , End with */
24
Q

What are variables used for?

A
  1. Containers for storing data values
25
Q

What does all JavaScript variables must be identified with?

A
  1. Unique names
    • It is called Identifiers
  • Can be short names ( x , y ) or more descriptive names ( age, sum, totalVolume )
26
Q

List out general rules for construction names for variables ( 6 )

A
  1. Names can contain letters, digits, underscores, and dollar sign
  2. Names must begin with a letter
  3. Names can also begin with $ and _
  4. Names are case sensitive
  5. Reserved words ( JS Keywords ) cannot be used as names
  6. JavaScript identifiers are case-sensitive
27
Q

What keyword can we use to declare JavaScript variable? ( 3 )

A
  1. var
  2. let
  3. const
  • let and const are added in 2015
28
Q

How to create a variable using the var keyword?

A
  1. var carName
  • The variable has no value ( Technically it has the value of undefined )

carName = “Volvo” to assign data with the assignment operator

var carName = “Volvo” assign a variable when we declare it

29
Q

List out 4 dataTypes that the var keyword can handle

A
  1. String
  2. Numbers
  3. Array
  4. Object
  • And more
30
Q

How to assign string John Doe to var userName?

A
  1. var userName = “John Doe”;
  • Can use “” or ‘’ ( Double / Single Quotes )
  • var ans = “He is called ‘Johnny’” / ‘He is called “Johnny”’
  • We cannot type “He is called “Johnny””
31
Q

How to assign value 30 to variable age?

A
  1. var age = 30;
  • Decimals
    var price = 29.99
  • Exponential
    var y = 123e5 ( 12300000 )
    var z = 123e-5 ( 0.00123 )
32
Q

What is the dataType for user input?

33
Q

What method is available to convert user input string value into number? ( 3 )

A
  1. Number()
    • Converts an object’s value to a number
  2. parseFloat()
    • Parses a string and returns a floating point number
  3. parseInt()
    • Parses a string and returns an integer

Number(“10”);
parseInt(“-10”);
parseInt(“10 20”);
parseInt(“10 Years”);

34
Q

What symbols are used to write Arrays?

A
  1. Square Brackets []
35
Q

How to declare a variable cars to store 3 values Saab, Volvo and BMW?

A
  1. var cars = [“SAAB” , “Volvo” , “BMW”]
  • Array items are seperated by commas
36
Q

What symbols are used to write JavaScript objects?

A
  1. Curly braces {}
37
Q

How to create an objects that stores user first / last name, age and eye color?

A
  1. var person = { firstName : “John” , lastName : “Doe” , age : 50, eyeColor : “Blue”}