Search Header Logo
Learn Javascript (1)

Learn Javascript (1)

Assessment

Presentation

Computers

6th - 8th Grade

Practice Problem

Easy

Created by

cam darr

Used 4+ times

FREE Resource

6 Slides • 16 Questions

1

JavaScript (1)

By cam darr

2

What is JavaScript?

JavaScript (JS) is a programming language that makes websites interactive. It allows you to:

  • Show alerts and messages

  • Create animations

  • Handle user input (e.g., button clicks)

  • Update webpage content dynamically

It runs in web browsers, meaning you don’t need to install anything special to start coding.

Running JavaScript

You can run JavaScript in two simple ways:

A. Using the Browser Console

  1. Open a web browser (Chrome, Firefox, Edge, etc.).

  2. Right-click on a webpage and select Inspect (or press F12 or Ctrl + Shift + I).

  3. Go to the Console tab.

  4. Type this and press Enter:

    This prints a message to the console.

media

3

media

Variables store data. You can create them using let, const, or var.

  • let allows changing the value later.

  • const is for values that don’t change.

  • var is older and mostly avoided.

Try this in your browser console:

​Variables

media

When a variable is declared, but not defined it will always output "undefined" when printed in the console.

For example:
let x;

console.log(x);

​You can also print multiple variables in the console using commas. In this example it prints: "Alice 25"

4

Multiple Choice

Which keyword is used to declare a variable that can change later?

1

const

2

var

3

let

5

Multiple Choice

Which keyword is used to declare a variable that cannot change?

1

const

2

var

3

let

6

Multiple Choice

Question image

What will be printed in the console?

1
red
2

error

3

undefined

4
blue

7

Multiple Choice

Question image

What's wrong with this code? Fix it so it runs correctly.

1

let city = "Los Angeles";

console.log('city');

2

let city = "New York";

console.log(city);

3

let city = "New York";

city = "Los Angeles";

console.log(city);

4

const city = "Los Angeles";

city = "New York";

8

Multiple Choice

Question image

What will be printed in the console?

1

Error

2
undefined
3
null
4

false

9

JavaScript Data Types

JavaScript has different types of data that you can store in variables. Here are the main ones:

media
media

​When this is printed it will look something like this:
Hello 30 true undefined null Array (3)
0: "apple"
1: "banana"
2: "cherry"
length: 3
Object
age: 25
name: "Alice"

Note: Objects are printed alphabetically. In the example age is first and then name.

10

JavaScript Operators

Operators are used to perform operations on variables and values. Don't forget that coding will involve a lot of math!
Arithmetic Operators (Math Operations):

media
media
media

Comparison Operators (True/False Checks)

media

​Still don't get it? This key might help:
= means "equal"
! means "not"
> means "greater than"
< means "less than"

11

media

​Logical Operators

​Logical operators in JavaScript are used to perform logical operations between two or more values. They help to evaluate conditions and return boolean values (true or false). These operators are essential in controlling the flow of logic in decision-making structures like if statements, loops, and other conditional expressions.

AND (&&)

  • The AND operator is used to check if both conditions are true. If both conditions are true, it returns true; otherwise, it returns false.

  • Syntax: condition1 && condition2

  • Example:

    true && false // returns false

OR (||)

  • The OR operator is used to check if at least one of the conditions is true. If either condition is true, it returns true. If both are false, it returns false.

  • Syntax: condition1 || condition2

  • Example:

    true || false // returns true

NOT (!)

The NOT operator is used to reverse the boolean value of a condition. If the condition is true, it becomes false, and vice versa.

Syntax: !condition

Example:

!true // returns false

These logical operators are commonly used in if statements to evaluate multiple conditions:

let age = 25;
let hasPermission = true;

if (age >= 18 && hasPermission) {
console.log("You can enter.");
}

In this example, the && operator checks if both age >= 18 and hasPermission are true before allowing entry.

Short-Circuiting

Logical operators in JavaScript have short-circuit behavior:

  • AND (&&): If the first condition is false, the second condition is not evaluated.

  • OR (||): If the first condition is true, the second condition is not evaluated.

This feature can improve performance by preventing unnecessary evaluations of conditions.

media

12

Multiple Choice

Which of the following is a valid example of a String in JavaScript?

1

true

2

42

3

"Hello, World!"

4

{ name: "Alice" }

13

Multiple Choice

What is the type of the variable let isHappy = true;?

1

Number

2

Boolean

3

String

4

Undefined

14

Multiple Choice

Question image

What will be the output of the following code? (Hint: Objects are printed alphabetically)

1

Hello 30 true undefined null ["apple", "banana", "cherry"] { , age: 25, name: "Alice" }

2

Hello 30 true NaN null ["apple", "banana", "cherry"] { , age: 25, name: "Alice" }

3

Hello, true, 30, undefined, null, ["apple", "banana", "cherry"], { name: "Alice", age: 25 }

4

30 true undefined NaN null ["apple", "banana", "cherry"] { name: "Alice", age: 25 }

15

Multiple Choice

What will be the result of 10 % 3?

1

3

2

1

3

0

4

10

16

Multiple Choice

Which operator is used for exponentiation (power) in JavaScript?

1

* (asterisk)

2

** (double asterisk)

3

% (percent)

4

^ (caret)

17

Multiple Choice

Question image

What will the following code output?

1

100

2

30

3

1000

4

7

18

Multiple Choice

Question image

What will be the output of the following code?

1

true false

2

false true

3

true true

4

false false

19

Multiple Choice

Which operator checks both the value and type of two variables?

1

==

2

!=

3

===

4

!==

20

Multiple Choice

Question image

What will be the result of the following expression?

1

true

2

false

3

undefined

4

NaN

21

Multiple Choice

Question image

What is the output of the following code?

1

false

2

true

3

undefined

4

NaN

22

Multiple Choice

Question image

The following code doesn't work properly:

1

Replace !true with true!

2

Replace !true with false

3

Replace !true with !false

JavaScript (1)

By cam darr

Show answer

Auto Play

Slide 1 / 22

SLIDE