You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

175 lines
4.7 KiB
JavaScript

console.log("Hello B322");
// Console.log() ise useful for printing values of variables or results into the browser's console.
let myVariable;
myVariable = 'Hello';
// Trying to print out a value of a variable that has not been declared will return of "not defined"
console.log(myVariable);
// The "not defined" error in the console refers to the variable not being created /defined, whereas in the previous example the code refers to the "value" of the variable as not defiend.
let hello;
hello = "Hello";
console.log(hello);
// Naming Variables
// let FirstName = "Michael"; - bad variable name
// let firstName = "Michael"; - good variable name
// let product_description = "lorem ipsum" good variable name
// Declaring and initializing variables
let productName = 'desktop computer';
console.log (productName);
let seatsInTheatres = '10';
console.log()
// let variable cannot be re-declared within its scope.
// let friend = 'kate';
// let friend = 'jane'; - would cause an error.
// console.log(friend);
let friend = 'Kate'; // Straight declaration
friend = 'Jane';
console.log(friend);
let supplier; // Variable is a container
// Initialization is done after the variable has been declared.
supplier = 'John Smith Tradings';
console.log(supplier);
const interest = 3.539;
console.log(interest);
// You can't declare a const variable using initialization
// const pi;
// pi = 3.1416;
// console.log(pi);
// SECTION Data types
// Strings
let country = 'Philippines';
let province = "Metro Manila";
// Concatenating strings
// Multiple string values can be combined to create a single string using + symbol.
let fullAddress = province + ',' + country; // use '' for as a string
console.log(fullAddress);
let greeting = 'I live in the ' + country;
console.log(greeting);
let string = "Hello";
let number = 42;
let result = string + " " + number;
console.log(result);
// Escape character "\"
let mailAddress = 'Metro Manila\n\nPhilippines';
console.log(mailAddress);
let message = "John's employees went home early";
console.log(message);
message = "John's employees went home early"; // you can also use 'John\'s'
console.log(message);
// Numbers
// Integers / Whole Numbers
let headcount = 26;
console.log(headcount);
// Decimal Numbers/Fractions
let grade = 98.7;
console.log(grade);
// Exponential Notation
let planetDistance = 2e10;
console.log(planetDistance);
console.log("John's grade last quarter is " + grade);
// Boolean
// Boolean values are normally used to store values relating to the state of certain things, this would be useful for logics.
let isMarried = false;
let inGoodConduct = true;
console.log("isMarried: " + isMarried);
console.log("isGoodConduct: " + inGoodConduct);
// Arrays
/// Arrays are a special kind of data type that's used to store multiple values
// Arrays can store different data types but is normally used to store similar data types.
let grades = [98.7, 92.1, 90.2, 94.6];
console.log(grades);
// Different data types
// Storing different data types inside an array is not recommended because it nwill not make sense in the context of programming
let details = ["John", "Smith", 32, true];
console.log(details);
// Objects
// Objects are another special kind o fdata type that's used to mimic real world objects/items.
let person = {
fullName: 'Juan Dela Cruz',
age: 35,
isMarried: false,
contact: ["+63917 123 4567", "8123 4567"],
address: {
houseNumber: '345',
city: 'Manila'
}
};
console.log(person);
// typeof
console.log(typeof person);
let myGrades = {
firstGrading: 98.7,
secondGrading: 92.1,
thirdGrading: 90.2,
fourthGrading: 94.6
}
console.log(myGrades);
// Null
// It is used to intentionally express the absence of a value in variable declaration/initialization
// Null simply means that a data type was assigned to a variable but it does not hold any value/amount or is nullified
let spouse = null;
console.log(spouse);
// Using null compared to 0 value and an empty string is much better for readability purposes
// Null is also considered as a data type of it's own compared to 0 which is a data type of a number and a single quotes which are a data type of a string.
let myNumber = 0;
console.log(myNumber);
let myString = '';
console.log(myString);
// Undefined
let fullName;
console.log(fullName);
// Undefiend vs Null
// One clear difference between undefined and null is that for undefined, a variable was created but was not provided a value but, null means that a variable was created and was assigned a value that does not hold any value/ amount.
// certain processes in programming would often return a "null" value when certain tasks results to nothing.
let varA = null;
console.log(varA);
let varB;
console.log(varB);