30 Days Of JavaScript.1
Day 1. Introduction
On
day 1
, I learned the basics of the basics of JavaScript. I wrote some notes on my notebook, and this post will contain features that I think are important to remember.
1. console.log()
- can take multiple arguments
- the arguments are strings(texts)
- single quotes(‘ ‘), double quotes(“ “), back-ticks(``)
2. Comments
- single line comment
// this is a single line comment.
- multiline comment
/* you can put multiple lines of comments, using these symbols. */
3. Arithmetics
On console(how to open:Ctrl+Shift+I
), I can use these operators without console.log
, but in text editor I should use console.log
.
- multiplication(*)
- division(/)
- addition(+)
- subtraction(-)
- modulus(%) - finding remainder
- exponentation(**) ex) 3 ** 2 = 9
4. Adding Javascript to a web page
1) Inline script
<body>
<button onclick = "alert('Welcome!')">Click me<button>
</body>
2) Internal script
- could be written in both head/body
<script>
console.log('Welcome!');
</script>
3) External script (create an external JavaScript file)
- could be written in both head/body
<body>
<script src = "introduction.js"></script>
</body>
- before the closing tag(
</body>
) is recommended place to put JavaScript code
4) Multiple external scripts
- you can add several JS files
- ⚠️your main.js file should be below all other scripts(should be written last)
5. Introduction to Data Types
Primitive Types
- Numbers - both integers(-,0,+) and float-point numbers
- Strings - any data types under ‘ ‘, “ “, ``
- Boolean - true / false
- undefined
- default value if we don’t assign any value to a variable
- if a function is not returning anything, it returns undefined
- null - an empty value
6. Variables
To declare a variable
A variable is a container of data. It stores the memory data of the location. When a variable is declared, the memory space is reserved. When the variable is assigned to a value(= a data), the memory space is filled.
To declare variable, we can use var
, let
, and const
.
var
is not recommended, let
is for variables that changes at a different time, and const
is for datat that doesn’t change at all(e.g. PI, gravity).
Variable naming rules
The name of a variable…
- doesn’t begin with number
- doesn’t allow special characters except $ and _
- follows a camelCase convention(cf. CamelCase for declaring classes)
- doesn’t have space between words
/*
'=' is called an assignment operator,
and the value is called an assigned data.
*/
let nameOfVariable = value;
- Variables can be declared in one line seperated by comma, but it’s recommended to use a seperate line to make the code more readable.
Leave a comment