{ "@context": "https://schema.org", "@type": "Organization", "name": "Brainscape", "url": "https://www.brainscape.com/", "logo": "https://www.brainscape.com/pks/images/cms/public-views/shared/Brainscape-logo-c4e172b280b4616f7fda.svg", "sameAs": [ "https://www.facebook.com/Brainscape", "https://x.com/brainscape", "https://www.linkedin.com/company/brainscape", "https://www.instagram.com/brainscape/", "https://www.tiktok.com/@brainscapeu", "https://www.pinterest.com/brainscape/", "https://www.youtube.com/@BrainscapeNY" ], "contactPoint": { "@type": "ContactPoint", "telephone": "(929) 334-4005", "contactType": "customer service", "availableLanguage": ["English"] }, "founder": { "@type": "Person", "name": "Andrew Cohen" }, "description": "Brainscape’s spaced repetition system is proven to DOUBLE learning results! Find, make, and study flashcards online or in our mobile app. Serious learners only.", "address": { "@type": "PostalAddress", "streetAddress": "159 W 25th St, Ste 517", "addressLocality": "New York", "addressRegion": "NY", "postalCode": "10001", "addressCountry": "USA" } }

JavaScript: Variables and Data Types Flashcards

(20 cards)

1
Q

What is JavaScript?

A

While HTML and CSS provide website structure, JavaScript brings interactivity to websites by enabling complex functionality, such as handling user input, animating elements, and even building full web applications.

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

What are DataTypes in JavaScript?

A

Data types help the program understand the kind of data it’s working with, whether it’s a number, text, or something else.

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

What is a Number in JavaScript?

A

A number represents both integers and floating-point values. Examples of integers include 7, 19, and 90.

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

What is a Floating Point in JavaScript?

A

A floating point number is a number with a decimal point. Examples include 3.14, 0.5, and 0.0001.

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

What is a String in JavaScript?

A

A string is a sequence of characters, or text, enclosed in quotes. “I like coding” and ‘JavaScript is fun’ are examples of strings.

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

What is a Boolean in JavaScript?

A

A boolean represents one of two possible values: true or false. You can use a boolean to represent a condition, such as isLoggedIn = true.

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

What are Undefined and Null in JavaScript?

A

An undefined value is a variable that has been declared but not assigned a value. A null value is an empty value, or a variable that has intentionally been assigned a value of null.

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

What is an Object in JavaScript?

A

An object is a collection of key-value pairs. The key is the property name, and the value is the property value.

Here, the pet object has three properties or keys: name, age, and type. The values are Fluffy, 3, and dog, respectively.

let pet = {
name: “Fluffy”,
age: 3,
type: “dog”
};

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

What is a Symbol in JavaScript?

A

The Symbol data type is a unique and immutable value that may be used as an identifier for object properties.

In this example below, two symbols are created with the same description, but they are not equal.

const crypticKey1= Symbol(“saltNpepper”);
const crypticKey2= Symbol(“saltNpepper”);
console.log(crypticKey1 === crypticKey2); // false

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

What is a BigInt in JavaScript?

A

When the number is too large for the Number data type, you can use the BigInt data type to represent integers of arbitrary length.

By adding an n to the end of the number, you can create a BigInt.

const veryBigNumber = 1234567890123456789012345678901234567890n;

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

What are Variables in JavaScript?

A

Variables can be declared using the let keyword.
let cityName;
To assign a value to a variable, you can use the assignment operator =.
cityName = “New York”;

Variables declared using let can be reassigned a new value.
cityName = “Los Angeles”;
console.log(cityName); // Los Angeles

Apart from let, you can also use const to declare a variable. However, a const variable cannot be reassigned a new value.
const cityName = “New York”;
cityName = “Los Angeles”; // TypeError: Assignment to constant variable.

Variables declared using const find uses in declaring constants, that are not allowed to change throughout the code, such as PI or MAX_SIZE.

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

What are Variable Naming Conventions in JavaScript?

A

Variable names should be descriptive and meaningful.
Variable names should be camelCase like cityName, isLoggedIn, and veryBigNumber.
Variable names should not start with a number. They must begin with a letter, _, or $.
Variable names should not contain spaces or special characters, except for _ and $.
Variable names should not be reserved keywords.
Variable names are case-sensitive. age and Age are different variables.

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

What are Strings in JavaScript?

A

Strings are sequences of characters enclosed in quotes. They can be created using single quotes and double quotes.
let correctWay = ‘This is a string’;
let alsoCorrect = “This is also a string”;

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

What is String Immutability in JavaScript?

A

Strings are immutable in JavaScript. This means that once a string is created, you cannot change the characters in the string. However, you can still reassign strings to a new value.
let firstName = “John”;
firstName = “Jane”; // Reassigning the string to a new value

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

What is String Concatenation in JavaScript?

A

Concatenation is the process of joining multiple strings or combining strings with variables that hold text. The + operator is one of the simplest and most frequently used methods to concatenate strings.
let studentName = “Asad”;
let studentAge = 25;
let studentInfo = studentName + “ is “ + studentAge + “ years old.”;
console.log(studentInfo); // Asad is 25 years old.

If you need to add or append to an existing string, then you can use the += operator. This is helpful when you want to build upon a string by adding more text to it over time.
let message = “Welcome to programming, “;
message += “Asad!”;
console.log(message); // Welcome to programming, Asad!

Another way you can concatenate strings is to use the concat() method. This method joins two or more strings together.
let firstName = “John”;
let lastName = “Doe”;
let fullName = firstName.concat(“ “, lastName);
console.log(fullName); // John Doe

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

What is “console.log()” in JavaScript?

A

The console.log() method is used to log messages to the console. It’s a helpful tool for debugging and testing your code.
console.log(“Hello, World!”);
// Output: Hello, World!

17
Q

What are Semicolons in JavaScript?

A

Semicolons are primarily used to mark the end of a statement. This helps the JavaScript engine understand the separation of individual instructions, which is crucial for correct execution.
let message = “Hello, World!”; // first statement ends here
let number = 42; // second statement starts here

Semicolons help prevent ambiguities in code execution and ensure that statements are correctly terminated.

18
Q

What are Comments in JavaScript?

A

Any line of code that is commented out is ignored by the JavaScript engine. Comments are used to explain code, make notes, or temporarily disable code.

Single-line comments are created using //.
// This is a single-line comment and will be ignored by the JavaScript engine

Multi-line comments are created using /* to start the comment and / to end the comment.
/

This is a multi-line comment.
It can span multiple lines.
*/

19
Q

What does it mean that JavaScript is a Dynamically Typed Language?

A

JavaScript is a dynamically typed language, which means that you don’t have to specify the data type of a variable when you declare it. The JavaScript engine automatically determines the data type based on the value assigned to the variable.

let error = 404; // JavaScript treats error as a number
error = “Not Found”; // JavaScript now treats error as a string

Other languages, like Java, that are not dynamically typed would result in an error:
int error = 404; // value must always be an integer
error = “Not Found”; // This would cause an error in Java