Intro to Javascript Flashcards
What is the purpose of the console in JavaScript?
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 does the console object work in JavaScript?
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.
What is a keyword in JavaScript, and how is it related to the console?
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.
What is the console.log() method used for?
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 would you log the value 5 to the console using console.log()?
To log the value 5 to the console using console.log(), you would write: console.log(5);
Why is it recommended to end each statement with a semicolon in JavaScript?
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.
Can you provide an example of printing a different kind of data using console.log()?
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 many fundamental data types are there in JavaScript, and what are they?
There are seven fundamental data types in JavaScript:
Number
String
Boolean
Null
Undefined
Symbol
Object
What is the difference between a string and a number data type in JavaScript?
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.
What are the two possible values of a boolean data type?
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 is the null data type represented in JavaScript?
The null data type represents the intentional absence of a value. It is represented by the keyword null.
What does the undefined data type represent in JavaScript?
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.
What are symbols used for in JavaScript?
Symbols are unique identifiers introduced in JavaScript. They are useful for creating unique property keys in objects and preventing naming conflicts.
What is the difference between primitive data types and objects in JavaScript?
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 many types of data are considered primitive data types in JavaScript?
Six data types (number, string, boolean, null, undefined, symbol) are considered primitive data types in JavaScript.