Basic Js
Basic Js
/*VARIABLES*/
/*
<p id="idName"></p> <-- declare id for an HTML element
<script> <-- javascript in HTML document goes in script element
let variableName = "variableValue"; <-- declare variable
document.getElementById("idName").innerHTML = variableName; <-- output
the value in HTML element
</script>
*/
/*FUNCTIONS*/
/*
function funcName(parameterName) {
return parameterName
}
*/
/*OBJECTS*/
//const objectName = {propertyName:propertyValue, propertyName:propertyValue};
<-- create object and it's properties
//objectName.propertyName to Access object property
//this.propertyName to Access the property of a local object
//"this" Refers to an object, like "self" in pyhton
//methods like call(), apply(), and bind() can refer "this" to any object.
/*EVENTS*/
/*STRING SYNTAX*/
// "this is a string"
// 'this is a string
// `this is a string`
// \b Backspace
// \f Form Feed
// \n New Line
// \r Carriage Return
// \t Horizontal Tabulator
// \v Vertical Tabulator
/*ARRAYS*/
/*DATES*/
//new Date()
//new Date(date string)
//new Date(year,month)
//new Date(year,month,day)
//new Date(year,month,day,hours)
//new Date(year,month,day,hours,minutes)
//new Date(year,month,day,hours,minutes,seconds)
//new Date(year,month,day,hours,minutes,seconds,ms)
//new Date(milliseconds)
//ISO dates can be written with added hours, minutes, and seconds (YYYY-MM-
DDTHH:MM:SSZ):
// the T seperates day and time, the Z defines UTC time
/*IF/ELSE STATEMENTS*/
//if (condition) {
// block of code to be executed if the condition is true}
// else {
// block of code to be executed if the condition is false}
/*CLASSES*/
/*JSON*/
/*DEBUG*/
// press F12 key in browser to activate debugging
// select Console in debugger menu to open console view
// use console.log() to display JavaScript values in the debugger window
// The log() method writes (logs) a message to the console and it useful
for testing
// console.log(message); <-- basic log method syntax
/* <-- example of using log method to write an object to the console
const objectName = {"field":value};
console.log(objectName);
*/