1.1 What Is JavaScript Flashcards
What Is JavaScript?
JavaScript (or simply JS) is the programming language of the web browser.
What is client-side programming?
the code runs on the client’s computer or device
What is server-side programming?
code is executed on a server and not on the user’s computer.
What does DOM stand for?
Document Object Model
The DOM, which stands for Document Object Model, is a programming interface for HTML.
What are functions?
functions are reusable pieces of code. Instead of writing the same code over and over again when you want to reuse it, you can put it inside a function and call the function where you need it.
What does the: alert() function do?
It’s predefined to open a pop-up in your browser.
()
Functions in JavaScript always have parentheses at the end, within which you can define custom parameters.
Click me!
onclick
onclick is a predefined HTML attribute.
Developer Tools Console
Option + Cmd + i
What happens:
alert(‘Hello world’);
pop-up with the text “Hello world”.
What happens:
console.log(‘Hello world’);
This function will print the given text to the console.
How do you clear the console screen?
“Cmd + L” or “Ctrl + L”.
Inline
“Inline JavaScript” means placing pieces of JavaSript directly into your HTML file, like this:
Click me!
Where should the tag go?
at the very bottom of the page, right before the closing body tag
Folder Structure:
simple-js-app:
css/ styles.css index.html js/ scripts.js
How do you include script in your “index.html” page?
at the very bottom of the page, right before the closing body tag
Comments in JS:
// - Single line comment
/* bla bla bla */
Where should comments be placed?
before the piece of code they reference.
What are Variables?
Variables are used to store—and later re-access—a piece of data, such as text or a number.
the value they store can be changed at any point in time.
var age = 29; var name = 'Anne';
console.log
Outputs to the console
Names of Variables must:
It must start with a letter
It can only consist of letters, numbers, or underscores (“_”)
It can’t include any special characters, such as ü or à
Examples:
age
myAge
my_age
addressLine2
Are Variables case sensitive?
Yes
Thus, myAge and myage would be two completely different variables. So would MY_AGE, and my_age.
var josesAge = 35; var lisasAge = josesAge;
you can assign one variable’s value to a second variable
var myName = 'John Doe'; myName = 'John Doe Jr';
You can also assign a new value to an existing variable
when changing the value of a variable, you simply start with the variable name and don’t use var.