JavaScript Overview Flashcards
What is a program?
A set of instructions for a computer to carry out.
We write programs to solve a specific problem or provide a specific experience. The skill of programming, therefore, has two steps: first, programming is finding solutions to problems; second, programming is implementing those solutions in a particular programming language so your computer can understand and execute your solution.
What is JavaScript?
JavaScript (JS) is a programming language available in all modern browsers. JS is an implementation of the ECMAScript standard.
We can use the JS programming language, which ECMA determines, to control the engine in a browser. The better you understand the programming language, the better you control the engine.
What is ECMA?
ECMA controls the standard for JavaScript programming language, which is called ECMAScript. All web browsers should have a JavaScript version that is ECMA compliant. Each web browser is responsible for interpreting the ECMAScript.
What is DOM API?
Document Object Model API
The part of JavaScript that deals with interacting with HTML elements. It’s specified by the W3C (World Wide Web Consortium), which is the same organization that creates the specification for HTML.
What is Chrome DevTools?
Chrome DevTools provides an interactive JavaScript console where you can run and debug code.
How do you open Chrome DevTools on a MAC?
Option + ⌘ + J
How do you open Chrome DevTools on a PC?
Ctrl + Shift + J
What is a variable?
A variable is a name that is attached to a value. Variables are used to create and represent data in our applications. (Variables are data in our apps.)
How does a variable work?
When you need to create data, you create a keyword. Use the var, let, or const keywords to create the data. Then you enter how you want the JS to represent the piece data it’s grabbing:
var someIdentifier
Then you give it an assignment operator:
var someIdentifier = ‘somevalue’;
So here we are telling it to grab this piece of memory (var) with this label (someIdentifier) and set it equal to this value (somevalue).
You can also write it in this way with an undeclared variable:
var someIdentifier;
someIdentifier = somevalue;
What is a constant?
A constant cannot be reassigned with a new value. It’s used to define constant values, which is another way of saying variables whose value cannot be reassigned.
You can declare it in JS by entering “const”:
const someIdentifier = ‘somevaluethatwon’teverchange’
The defining feature of a constant is that its value cannot be changed, and the browser enforces this behavior. When you try to change the value of a constant, you’ll get an error.
In JavaScript, what are the 3 commands we can use to declare space in memory where we’ll store values?
var
let
const
In JavaScript, what does the equal sign (=) mean?
Assignment operator
What is let or var?
These are used to define variables with values that can (but don’t have to) be changed or reassigned.
How can you declare a variable without an assignment operator? What does this do?
var someIdentifier;
When you declare a variable without an assignment operator, it has no value yet.
What value does JavaScript give declared but unassigned variables?
undefined
What are two rules for naming variables?
Reserved words: You can’t use reserved words in a variable name. For example, you can’t reassign the name var to a new rule like this:
var var = ‘some value’;
However, you can use a reserved word as part of a name though it might be redundant:
var varFoo;
Character restrictions: A variable name must begin with an upper or lower case letter, $, or _. It cannot begin with a number. Spaces cannot appear anywhere in the variable name. Comparison and logical operators cannot be used in variable names. So these are unacceptable:
let my Foo = ‘bar’;
let my+Foo;
Numbers can appear in a variable name, so this is acceptable:
let myFoo2;
What are two important stylist guidelines when writing your code in JavaScript?
Use camelCasing: A camel-cased variable name starts with a lowercase letter, and then uses lowercase letters throughout, except for the first letter of any new words in the variable name after the first — for these first letters, use uppercase.
Use meaningful variable names: Choose names that reflect how the variable gets used in the program. A well-chosen variable name can help other people reading the code to understand how the variable is intended to be used.
How can you force JavaScript to avoid global variables?
At the top of your JavaScript, enter this:
‘use strict’;
What is a global variable, and why should you avoid it?
A global variable is when you enter the variable without the keyword like var or let. Here is an example:
foo = ‘bar’;
The proper way is this:
let foo=’bar’;
Global variables tend to make code buggier and harder to reason about.
What is a data type?
A data type is a value that variables can have. Data types help us organize our data because there is a lot.
How many data types are there and what are they?
There are 6 different data types:
String Number Boolean Null Undefined Object
Note: Functions are not always considered a data type by everyone.
What is coercion?
How variables are converted from one type to another in JavaScript. For example:
const stringVar = 'Kilroy was here '; const numVar = 12;
const combined = stringVar + numVar; typeof combined; // => string console.log(combined); // => Kilroy was here 12
The example above demonstrates that if you combine a number with a string using the + operator, the resulting value will be a string.
What is typeof in JavaScript?
It’s a built-in command JavaScript provides to see the data type of a particular value. So if you run typeof 2, the result would be “number”.
What is the string data type?
Strings are used to represent text. They include opening and closing quotes (either single or double, but both must be the same kind — you can’t open with a single and close with a double). So. . .
let foo = ‘bar’;
and
let bar = “foo”;
are both valid.