What is JavaScript (JS)
- Javascript is a front-end programming language that creates interactive experiences and moving pieces on a website.
- Not to be confused with Java which is a back-end language.
- It was created in 1995 and is supported across all browsers.
- Enables sophisticated interactions between users and browsers to color the web with more features than just text- something that HTML, CSS, Java, C++ etc. were not able to provide.
- JavaScript is a ‘weakly typed’ language. In this case, the ‘type’ refers to data types, not the keyboard. This means that, unlike other languages which are very type specific such as Python or C++, JavaScript is a bit more flexible in that it can sometimes guess which data type you intended to use depending on the implications of your function.
- Does not need to communicate with the back-end/server side of a browser to execute input/responses so interactions can be made smoothly and swiftly.
- Think of this analogy: if HTML is the framework of a house and CSS is the décor, wall paper, etc., then Javascript is like the electricity, the opening doors and everything else that makes the house interactive and animated.
JavaScript Syntax
CAPITALIZATION
• JavaScript is case-sensitive
• Uses camel case (i.e. camelCase) for stringing multiple word names together. The first letter is lowercase and any following words in the label would be capitalized.
PUNCTUATION
• Most lines end with a semicolon; It used to be that all lines always ended in a semicolon but the language is ever-evolving and some newer iterations don’t always requite semicolons and have other style guides that organize the text.
• One of the few times a line would end in a comma is at the end of a key-value statement within an object.
ORDER OF ARITHMETIC OPERATIONS
• JavaScript will follow the order of operations in math, also known as PEMDASS which stands for Parentheses, Exponents, Multiply, Divide, Add, Subtract
CONCATENATION OF STRING VALUES
• Strings are a value that can contain numbers or letters. They are identified by using single or double quotation marks around them. It might be best practice to use doubles in case any words contain an apostrophe that would accidentally close a single quote phrase.
• Concatenation is the act of combining strings. Use a + sign to combine strings with other variables. Add a space where necessary with a “ “ to make readable concatenated phrases.
const firstName = "Lisa"; const lastName = "Simpson";
We can easily do this by using a + sign, like so:
console.log(firstName + " " + lastName);