Bird
Raised Fist0
Javascriptprogramming~20 mins

What is JavaScript - Practice Questions & Exercises

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
JavaScript Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:00remaining
What is JavaScript used for?

JavaScript is a popular programming language. What is its main use?

ATo style web pages with colors and fonts
BTo create databases for storing data
CTo write server operating systems
DTo add interactivity and dynamic behavior to web pages
Attempts:
2 left
💡 Hint

Think about what happens when you click buttons or see animations on websites.

❓ Predict Output
intermediate
1:30remaining
What is the output of this JavaScript code?

Look at this code and choose the correct output.

Javascript
console.log(typeof []);
A"array"
B"list"
C"object"
D"undefined"
Attempts:
2 left
💡 Hint

In JavaScript, arrays are a type of object.

❓ Predict Output
advanced
1:30remaining
What is the output of this JavaScript code snippet?

What will this code print to the console?

Javascript
console.log(0.1 + 0.2 === 0.3);
Atrue
Bfalse
CTypeError
Dundefined
Attempts:
2 left
💡 Hint

Think about how computers handle decimal numbers.

🧠 Conceptual
advanced
1:00remaining
Which statement about JavaScript is true?

Choose the correct statement about JavaScript.

AJavaScript supports asynchronous programming with promises and async/await.
BJavaScript is a statically typed language.
CJavaScript can only run in web browsers.
DJavaScript code must be compiled before running.
Attempts:
2 left
💡 Hint

Think about how JavaScript handles tasks like fetching data from the internet.

❓ Predict Output
expert
2:00remaining
What is the output of this JavaScript code with closures?

What will this code print to the console?

Javascript
function makeCounter() {
  let count = 0;
  return function() {
    count += 1;
    return count;
  };
}
const counter1 = makeCounter();
const counter2 = makeCounter();
console.log(counter1());
console.log(counter1());
console.log(counter2());
A
1
2
1
B
1
1
1
C
0
1
0
D
2
3
2
Attempts:
2 left
💡 Hint

Each call to makeCounter creates a new independent counter.

Practice

(1/5)
1. What is JavaScript primarily used for on websites?
easy
A. To write the webpage content
B. To style the webpage layout
C. To add actions and interactivity
D. To store data on the server

Solution

  1. Step 1: Understand JavaScript's role

    JavaScript is a programming language that adds actions and interactivity to websites.
  2. Step 2: Compare with other web technologies

    HTML writes content, CSS styles layout, and server stores data, so JavaScript adds interactivity.
  3. Final Answer:

    To add actions and interactivity -> Option C
  4. Quick Check:

    JavaScript = Interactivity [OK]
Hint: JavaScript makes websites interactive, not just static [OK]
Common Mistakes:
  • Confusing JavaScript with CSS for styling
  • Thinking JavaScript writes webpage text
  • Assuming JavaScript stores server data
2. Which of the following is the correct way to include JavaScript in an HTML file?
easy
A. <link href='app.js'>
B. <script src='app.js'></script>
C. <js>app.js</js>
D. <style>app.js</style>

Solution

  1. Step 1: Identify correct HTML tag for JavaScript

    The <script> tag is used to include JavaScript files or code in HTML.
  2. Step 2: Check the options

    <script src='app.js'></script> uses <script src='app.js'></script>, which is correct syntax to include an external JS file.
  3. Final Answer:

    <script src='app.js'></script> -> Option B
  4. Quick Check:

    Use <script> for JavaScript [OK]
Hint: JavaScript files go inside <script> tags [OK]
Common Mistakes:
  • Using <style> tag for JavaScript
  • Using non-existent <js> tag
  • Using <link> tag which is for CSS
3. What will the following JavaScript code output in the browser console?
console.log('Hello, ' + 'world!');
medium
A. Hello, world!
B. Hello, + world!
C. Hello world!
D. Error

Solution

  1. Step 1: Understand string concatenation

    The + operator joins two strings into one continuous string.
  2. Step 2: Combine the strings

    'Hello, ' + 'world!' becomes 'Hello, world!'. console.log prints this to the console.
  3. Final Answer:

    Hello, world! -> Option A
  4. Quick Check:

    String + String = Combined string [OK]
Hint: Plus (+) joins strings in JavaScript [OK]
Common Mistakes:
  • Expecting plus sign to print
  • Missing comma or space in output
  • Thinking it causes an error
4. Find the error in this JavaScript code snippet:
function greet() {
console.log('Hi there!')
}
medium
A. Missing semicolon after console.log statement
B. Missing parentheses in function declaration
C. Missing curly braces around function body
D. No error, code is correct

Solution

  1. Step 1: Check function syntax

    The function greet() has parentheses and curly braces properly placed.
  2. Step 2: Check statement termination

    JavaScript allows optional semicolons; missing semicolon here does not cause error.
  3. Final Answer:

    No error, code is correct -> Option D
  4. Quick Check:

    Semicolons optional in JS [OK]
Hint: Semicolons are optional in many JS cases [OK]
Common Mistakes:
  • Thinking semicolon is always required
  • Confusing function syntax rules
  • Assuming missing semicolon causes error
5. You want to make a webpage respond when a user clicks a button. Which JavaScript concept should you use?
hard
A. Event handling
B. Variable declaration
C. CSS styling
D. HTML structuring

Solution

  1. Step 1: Understand user interaction

    Responding to clicks means reacting to user events on the page.
  2. Step 2: Identify JavaScript feature for user actions

    Event handling lets JavaScript listen and respond to user actions like clicks.
  3. Final Answer:

    Event handling -> Option A
  4. Quick Check:

    User clicks = Event handling [OK]
Hint: Use event handlers to react to user actions [OK]
Common Mistakes:
  • Confusing CSS styling with interactivity
  • Thinking variables handle clicks
  • Assuming HTML alone manages user actions
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard