Javascript Flashcards
(213 cards)
How many data types are there in Javascript?
7.
Number, String, Boolean, Null, Undefined, Symbol Object
Operator
An operator is a character that performs a task in our code.
String Concatenation
Operators aren’t just for numbers! When a + operator is used on two strings, it appends the right string to the left string:
console.log(‘hi’ + ‘ya’); // Prints ‘hiya’
console.log(‘wo’ + ‘ah’); // Prints ‘woah’
console.log(‘I love to ‘ + ‘code.’)
// Prints ‘I love to code.’
.length
Use the .length property to log the number of characters in the following string to the console:
Ways to call methods
We call, or use, these methods by appending an instance with:
a period (the dot operator)
the name of the method
opening and closing parentheses
.toUpperCase
console.log(‘hello’.toUpperCase()); // Prints ‘HELLO’
Math.random
Math.random generates a random number between 0 and 1.
Math.floor()
Then, Math.floor() rounds the number down to the nearest whole number.
console.log().
Data is printed, or logged, to the console, a panel that displays messages, with console.log()
var
var, short for variable, is a JavaScript keyword that creates, or declares, a new variable.
myName
myName is the variable’s name. Capitalizing in this way is a standard convention in JavaScript called camel casing. In camel casing you group words into one, the first word is lowercase, then every word that follows will have its first letter uppercased. (e.g. camelCaseEverything).
const entree = 'Enchiladas'; console.log(entree);
Proper syntax for constant variable console.log
var favoriteFood = ‘pizza’;
Declaring a variable syntax
Declaring a variable syntax
var favoriteFood = ‘pizza’;
var numofSlices = 8;
Syntax for assigning a number to a var (no’ ‘)
Declare a variable named numOfSlices using the var keyword and assign to it the number 8.
Syntax for assigning a number to a var (no’ ‘ marks like text)
Declare a variable named numOfSlices using the var keyword and assign to it the number 8.
var numofSlices = 8;
var favoriteFood = 'pizza'; console.log(favoriteFood);
How to properly console log a variable
How to properly console log a variable
var favoriteFood = 'pizza'; console.log(favoriteFood);
var favoriteFood = 'pizza'; console.log(favoriteFood);
var numOfSlices = 8; console.log(numOfSlices);
Console logging words vs. Console logging a var w/ numerical value
Console logging words vs. Console logging a var w/ numerical value
var favoriteFood = 'pizza'; console.log(favoriteFood);
var numOfSlices = 8; console.log(numOfSlices);
assign a var a boolean value
let changeMe = true
let changeMe = true
How to assign a var a bullian value
How to console.log a variable
let changeMe = false; console.log('changeMe')
let changeMe = false; console.log('changeMe')
How to console log a variable
${data.drinks[i].strDrink}
? h2.innerText = e.pics.p.innerText } ``` ``` }) .catch(err => { console.log(`error ${err}`) }); }
```