JavaScript Flashcards

1
Q

What is JavaScript and what is it used for?

A

JavaScript is a programming language used to make web pages interactive. Instead of static pages, JS lets pages respond to user actions.

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

How do you declare a variable in JavaScript?

A

You can declare a variable using the var keyword, like var name;, however, modern JS also allows you to use let for variables that change and const for constants. Generally don’t use var as it is globally scoped.

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

What is the DOM in the context of JavaScript?

A

DOM stands for Document Object Model . It is a tree structure that represents all web page elements. JS uses the DOM to interact with and change a web page’s content, structure, or style in real time.

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

Explain the purpose of callback functions in JS?

A

A callback function is a function passed into another function as an argument. It is then called (or executed) inside of the outer function. Sometimes you want to make sure certain actions finish before another starts. Callbacks ensure tasks happen in the correct order, especially asynchronous tasks.

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

What is an event listener in JavaScript, and how do you use it?

A

An event listener waits for a specific event, like a button click on a webpage.

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

What is the ‘this’ keyword in JavaScript, and how does it work?

A

In JS, ‘this’ is a reference to the object that is currently interacting. Its value depends on how a function is called. Inside a method, ‘this’ refers to the owner object. In a stand-alone function, it is the global object. It is a way to access properties or methods of the current object.

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

Explain the difference between null and underlined?

A

In JavaScriot, both null and undefined mean no value. However, they’re used differently. Undefined means a variable exists but hasn’t been assigned a value yet. Null is a deliberate assignment, showing that the variable should have no value. Think of undefined as an accident, while null is intentional.

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