Chapter 2 - Basic Javascript Instructions Flashcards
What is a script?
A script is a series of instructions that a computer can follow one-by-one
Each individual instruction in a script is also known as?
A statement - an individual instruction that a computer should follow. Each one should start on a new line and end with a semi-colon. This makes your code easier to read & follow
Each of the statements or instructions in a script should be followed by a
semicolon
what do the pink curly braces in scripts represent?
they represent the start and end of a code block. statements can be organized into code blocks. the closing curly braces isn’t followed by a semi-colon
each code block could contain more than 1 statement - true or false?
true
Is javascript case-sensitive
yes
What are some of the reasons why you should comment in your code.
What are the methods that can be used to comment in a javascript code
to explain what your code does. they help your code easier to read & understand. this can help you & others who read your code
multi-line and single-line
How to write multi-line comments
to write a comment that stretches over more than one line… /…./. Anything between these characters is not processed by the Javascript character… they are often used for descriptions of how the script works, or to prevent a section of the script from running when testing it
how to write a single-line comment
anything that follows the two forward slash characters //….. often used for short descriptions of what the code is doing
What is a variable?
A script will have to temporarily store the bits of info it needs to do its job. It can store this data in variables.
What is the #1 thing to do when using a variable?
declare the variable: announce that you want to use it - create the variable and give it a name
how to declare a variable
var name;
var = variable keyword name = variable name (in order to use a variable, you must give it a name or an identifier. if a variable name is more than one word, it is usually written in camelcase - first word is all lower case and any subsequent words have their first letter capitalized)
how to assign values to variables?
once you’ve created a variable, you can tell it what info you would like it to store for you - you assign a value to the variable i.e. var quantity = 3; … you can now use the variable by its name. the equal sign is an assignment operator, it says you’re going to assign a value to the variable… until you’ve assigned a value to a variable, programmers say the value is undefined.
What are the javascript Data Types?
- Numeric Data Type: you’ll use numbers 0-9, no commas. Numbers aren’t only used for things like calculators, they’re also used for tasks such as determining the size of the screen, moving the position of an element on a page, or setting the amount of time an element should take to fade in.
- String Data Type: Consists of letters and characters. Enclosed between a pair of quotes (can be single or double but must match) - they’re frequently used to add new content into a page and they can contain html markup.
- Boolean Data Type: Can have one or two values: true or false. Booleans are helpful when determining which part of a script should run. Booleans are used when the value can only be true/false. You could also think of these values as on/off or 0/1: true is equivalent to on or 1, false is equivalent to off or 0. Also, Booleans are used when your code can take more than one path. Remember, different code may run in different circumstances
- Arrays
- Objects
- Undefined
- Null
What are some shorthand techniques for creating variables?
- Variables are declared and values assigned in the same statement.
- 3 variables are declared on the same line, then values assigned to each of them
- 2 variables are declared and assigned values on the same line. Then one is declared and assigned a value on the next line.
- Here, a variable is used to hold a reference to an element in the html page. This allows you to work differently with the element stored in that variable