Intro to Javascript Flashcards

1
Q

What is the purpose of the console in JavaScript?

A

The console in JavaScript is used as a panel to display important messages, such as errors, for developers. It allows developers to see the output or log messages generated by their code.

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

How does the console object work in JavaScript?

A

The console object in JavaScript is a built-in object that provides methods and properties for interacting with the console. It allows developers to log messages, execute commands, and perform various actions related to debugging and monitoring their code.

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

What is a keyword in JavaScript, and how is it related to the console?

A

In JavaScript, keywords are words that are built into the language and have special meaning. The console keyword refers to the console object, allowing developers to access its methods and properties.

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

What is the console.log() method used for?

A

The console.log() method is used to print or log messages to the console. It accepts a value or an expression as an argument and displays it in the console output. This method is commonly used for debugging purposes to check the values of variables or to display intermediate results.

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

How would you log the value 5 to the console using console.log()?

A

To log the value 5 to the console using console.log(), you would write: console.log(5);

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

Why is it recommended to end each statement with a semicolon in JavaScript?

A

It is recommended to end each statement with a semicolon in JavaScript as a best practice. While JavaScript does allow omitting semicolons in some cases, adding them consistently can help prevent unexpected issues and make the code easier to read and maintain.

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

Can you provide an example of printing a different kind of data using console.log()?

A

Example of printing a different kind of data using console.log():

Printing a string: console.log(“Hello, world!”);
Printing a boolean value: console.log(true);
Printing an array: console.log([1, 2, 3]);
Printing an object: console.log({ name: “John”, age: 25 });

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

How many fundamental data types are there in JavaScript, and what are they?

A

There are seven fundamental data types in JavaScript:

Number
String
Boolean
Null
Undefined
Symbol
Object

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

What is the difference between a string and a number data type in JavaScript?

A

A string data type represents a sequence of characters, such as letters, numbers, spaces, and symbols. It is denoted by single quotes (‘…’) or double quotes (“…”). A number data type represents numeric values, including integers and decimals. It is written without quotes.

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

What are the two possible values of a boolean data type?

A

The boolean data type has two possible values: true and false. It represents the logical states of “on” and “off,” or the answers to a “yes” or “no” question.

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

How is the null data type represented in JavaScript?

A

The null data type represents the intentional absence of a value. It is represented by the keyword null.

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

What does the undefined data type represent in JavaScript?

A

The undefined data type represents the absence of a value, but unlike null, it indicates that a variable or property has not been assigned a value.

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

What are symbols used for in JavaScript?

A

Symbols are unique identifiers introduced in JavaScript. They are useful for creating unique property keys in objects and preventing naming conflicts.

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

What is the difference between primitive data types and objects in JavaScript?

A

Primitive data types are the basic data types in JavaScript, including number, string, boolean, null, undefined, and symbol. Objects, on the other hand, are more complex and can hold collections of related data or key-value pairs.

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

How many types of data are considered primitive data types in JavaScript?

A

Six data types (number, string, boolean, null, undefined, symbol) are considered primitive data types in JavaScript.

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

In the example given, what is the data type of the value ‘Location of Codecademy headquarters: 575 Broadway, New York City’?

A

The data type of the value ‘Location of Codecademy headquarters: 575 Broadway, New York City’ is a string.

17
Q

In the example given, what is the data type of the value 40?

A

The data type of the value 40 is a number.

18
Q

How can you concatenate two strings together in JavaScript?

A

To concatenate two strings together in JavaScript, you can use the + operator.

19
Q

What operator is used for string concatenation?

A

The + operator is used for string concatenation in JavaScript.

20
Q

What is the result of the following code: console.log(‘hi’ + ‘ya’);?

A

The result of the code console.log(‘hi’ + ‘ya’); is ‘hiya’.

21
Q

How can you concatenate multiple strings together in a single expression?

A

You can concatenate multiple strings together in a single expression by using the + operator between each pair of strings.

22
Q

What is the purpose of including spaces when concatenating strings?

A

Including spaces when concatenating strings is important to ensure proper spacing between the concatenated strings. The computer will join the strings exactly as they are given.

23
Q

How would you concatenate the strings ‘front’ and ‘space’ to produce the result ‘front space’?

A

To concatenate the strings ‘front’ and ‘space’ to produce the result ‘front space’, you would write: console.log(‘front ‘ + ‘space’);

24
Q

How would you concatenate the strings ‘back’ and ‘space’ to produce the result ‘back space’?

A

To concatenate the strings ‘back’ and ‘space’ to produce the result ‘back space’, you would write: console.log(‘back’ + ‘ space’);

25
Q

How would you concatenate the strings ‘no’ and ‘space’ to produce the result ‘nospace’?

A

To concatenate the strings ‘no’ and ‘space’ to produce the result ‘nospace’, you would write: console.log(‘no’ + ‘space’);

26
Q

How would you concatenate the strings ‘middle’, a space, and ‘space’ to produce the result ‘middle space’?

A

To concatenate the strings ‘middle’, a space, and ‘space’ to produce the result ‘middle space’, you would write: console.log(‘middle’ + ‘ ‘ + ‘space’);

27
Q

How would you concatenate the strings ‘One’, ‘, ‘, ‘two’, ‘, ‘, and ‘three!’ to produce the result ‘One, two, three!’?

A

To concatenate the strings ‘One’, ‘, ‘, ‘two’, ‘, ‘, and ‘three!’ to produce the result ‘One, two, three!’, you would write: console.log(‘One’ + ‘, ‘ + ‘two’ + ‘, ‘ + ‘three!’);

28
Q

What are properties in JavaScript?

A

Properties in JavaScript are specific attributes or characteristics associated with a particular data type. They provide information or behaviors that can be accessed or manipulated.

29
Q

How are properties related to data types in JavaScript?

A

Properties are related to data types in JavaScript because each data type has its own set of predefined properties. Instances of a data type have access to these properties, which store specific information or behaviors.

30
Q

How can you access the properties of a data type in JavaScript?

A

Properties of a data type in JavaScript can be accessed by appending the data instance with a period (dot) operator, followed by the property name.

31
Q

What operator is used to access properties in JavaScript?

A

The dot operator (.) is used to access properties in JavaScript.

32
Q

What does the dot operator (.) do in JavaScript?

A

The dot operator (.) in JavaScript is used to access the properties or methods of an object or data instance.

33
Q

In the example given, what is the property being accessed?

A

In the example given, the property being accessed is ‘length’.

34
Q

What is the value of the property ‘length’ for the string ‘Hello’?

A

The value of the property ‘length’ for the string ‘Hello’ is 5, as the string ‘Hello’ contains five characters.

35
Q

How would you access the property ‘toUpperCase’ for a string instance?

A

To access the property ‘toUpperCase’ for a string instance, you would write: stringInstance.toUpperCase().

36
Q

Can properties be accessed for all data types in JavaScript?

A

No, not all data types in JavaScript have properties. Some data types, such as null and undefined, do not have any properties associated with them.

37
Q

How can properties be useful in programming tasks?

A

Properties can be useful in programming tasks as they provide access to built-in functionalities or information related to the data type. They allow manipulation, retrieval, and modification of specific attributes or behaviors associated with the data instances.