1/64
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Syntax
programming languages is similar to grammar in spoken languages
Syntax
It's a set of rules for how statements and instructions are correctly structured.
Syntax
These rules dictate how we write and organize JavaScript code, and understanding them is the first step towards writing functional and error-free JavaScript programs.
statement
JavaScript programs are built from instructions called _______
statement
A _________ could be a command that performs a specific action, like displaying something on the screen or performing a calculation.
semicolon ( ; )
Each statement in JavaScript is separated by a _______, much like how we use full stops to separate sentences in English.
Variables
a storage container for data values
store and manipulate data
They allow us to assign values, retrieve them, and perform operations on them
var
declare a variable that can be reassigned later
has a function scope
var
the original way to declare variables
function-scoped
accessible within the function where they are defined
hoisting
var declarations are moved to the top of their scope
let
similar to var, but it has block scope
cannot be re declared within the same scope
block scoped
meaning they are only accessible within the block (e.g., within {}) where they are defined
const
declare variables that should not be reassigned after their initial assignment
has block scope
used for variables that should remain constant throughout the program.
Reserved keywords
var, let, const, if, else, for, while, and function
comments
add notes or prevent certain lines of code from executing temporarily
comments
completely ignored by the JavaScript engine, meaning they're for developers' eyes only.
comments
They can be single line or span multiple lines
single line
one line comment
multiline
comments that span multiple lines
linear, top-to-bottom
all JavaScript programs follow a ________ execution model
String
Represents textual data and is enclosed in single or double quotes
Number
Represents numeric values and floating-point, including integers numbers.
Boolean
Represents either true or false
Null
Represents the intentional absence of any object value.
Undefined
Represents a variable that has been declared but not assigned a value.
Descriptive Names
Use this to reflect the purpose of the variable
Camel Case
where the first word is lowercase and each subsequent word starts with an uppercase letter
prompt
displays a dialog box that allows the user to enter data
String
By default, the prompt function returns a ________
parseFloat
collecting numerical input, you should convert the input to a number
toFixed method
This method formats a number to a specified number of decimal places
console.log
It allows us to print messages and values to the console
Template literals
readable and flexible way to embed variables and expressions within strings
backticks (` )
${}
They are enclosed by ________ rather than quotes and allow for easy interpolation of variables using ___ syntax
Arithmetic operators
allow us to perform mathematical operations on numbers
Addition (+) Operator
used to add two numbers together or to concatenate strings
Subtraction (-) Operator
subtract one number from another
Multiplication (*) Operator
multiply two numbers together.
Division (/) Operator
divide one number by another
Modulus (%) Operator
used to find the remainder of the division between two numbers
Exponentiation (**) Operator
used to raise a number to the power of another number
same operation as using the Math.pow function but is more concise.
increment (++)
increase the value of a variable by 1.
decrement (--)
decrease the value of a variable by 1.
Compound Assignment Operators
+=, -=, *=, /=, and **=
Compound Assignment Operators
perform an arithmetic operation and assign the result to the same variable in a single step
parseInt(string, radix)
Parses a string and returns an integer.
parseFloat(string)
Parses a string and returns a floating-point number.
Number(string)
Can be used to convert both integer and floating-point numbers.
Math.floor()
rounds a number down to the nearest integer.
Math.ceil()
rounds a number up to the nearest integer.
Math.round()
rounds a number to the nearest integer, depending on whether the fraction is greater than or less than 0.5.
Math.random()
generates a random floating-point number between 0(inclusive) and 1 (exclusive).
Math.max()
returns the largest of the numbers provided
Math.min()
returns the smallest of the numbers provided
Comparison operators
compare values and determine their relationship
Comparison operators
commonly used in conditional statements and loops
Equality Operators
used to compare two values for equality
Strict Equality Operator (===)
This operator checks if the values being compared are of the same type and have the same value.
Loose Equality Operator (==)
This operator performs type coercion, meaning it converts the values being compared to a common type before making the comparison. (equality)
Inequality Operators
used to compare two values for inequality
Strict Inequality Operator (!==)
This operator checks if the values being compared are of different types or have different values.
Loose Inequality Operator (!=)
This operator performs type coercion, meaning it converts the values being compared to a common type before making the comparison. (inequality)
Greater Than Operator (>) and Greater Than or Equal Operator (>=)
These operators compare whether one value is greater than or greater than or equal to another value
Less Than Operator (<) and Less Than or Equal Operator (<=)
These operators compare whether one value is less than or less than or equal to another value