markdown js_the_very_basics_public.md
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown js_the_very_basics_public.md相关的知识,希望对你有一定的参考价值。
[demo repl.it](#demo)
This course is designed as a primer for our JS In-Depth Series of Group Sessions. This is ideal for Design Track students, Developer students struggling to understand JavaScript or students with limited programming experience. We will cover the building blocks of programming with JavaScript. This course assumes little or no experience with JavaScript.First
## We have three primary goals today.
1. Walk away with a new mental model for learning and understanding JavaScript or any programming language for that matter.
2. Understand what is a variable
3. Understand what the heck is a function
1. What is a programming Language?
1. A new mental model for a programming language
* It's just a piece of software loaded onto a computer
* this software knows how to respond to specific commands. Just like most pieces of software we use every day.
* Difference is we don't use buttons and mouse clicks to control this software. Instead, we use what's known as a programming language that the piece of software understands
* This is commonly referred to as code
* Image for your new mental model
1. What is JavaScript?
* JavaScript the Engine aka a Virtual Machine
* *Virtual Machine, a fancy word for a piece of Software that can understand a programming language and control a computer hardware functionality
* Ecma Script the rules for a JavaScript Runtime / Engine
* The V8 JavaSctipt Engine ()
*
![V8](http://68.media.tumblr.com/fce010057ef1a9aa5081cbc39edcde02/tumblr_o5hgl5pguD1u8qr43o1_500.gif)
* JavaScript the programming language
* think of it as English but for Human to Computer communication
* we can control the JavaScript Engine / Machine with JS the programming language
*![What Is JS](https://media.giphy.com/media/q0nb3ccCH76BW/giphy.gif)
* Let's learn this new language so we can talk to the JavaScript runtime
* Your first chat with the JS runtime.
* Error: Undefined
* Error: Not Defined
* The more we know the language, the more we control the conversation, and what this piece of software called a JavaScript Engine will do in the environment it's running on.
* Different JavaScript Environments
* The Browser (Chrome with V8 engine)
* The Server (Node with the V8 engine
* Other Software ()
# JavaScript Basics?
## Two Main Rules
- Variables: Are used to create and represent data in our applications
- Functions Are used to create custom actions that the JS Engine can understand with just one word.
## Data
When we code, we need to represent, reason and work with data.
> So what is data? data type + data value = data in our code;
#### How do we create and use data in JS?
JavaScript, like most programming languages, give us a predefined set of data types
### Data Types (Basic)
https://javascript.info/types
There are 7 basic types in JavaScript.
* number: for numbers of any kind: integer or floating-point.
* string: for strings. A string may have one or more characters; there’s no separate single-character type.
boolean: for true/false.
null: for unknown values – a standalone type that has a single value null.
undefined: for unassigned values – a standalone type that has a single value undefined.
object: for more complex data structures.
symbol: for unique identifiers.
The typeof operator allows us to see which type is stored in the variable.
Important Built-In Complex Types
- function
- arrays
* We can create custom types too.
![See About Built-In Custom Object Types](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects)
## Why do we need data types?
Data types to take up memory? Some data types take up more than others. The JS engine can leverage this info to help us efficiently manage the computer memory our data is using. Also, by having specific types, it allows us to have predefined actions for each type. When we have a particular data type in JavaScript, we know there are particular actions the JavaScript engine knows how to take on this data type.
Example (data tpye | common actions):
- strings: `toLowerCase()`,`includes()`, `charAt()`, `replace()`
- [Learn More](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
- number: `isNaN()`, `toString()`, `toFixed()`
- [Learn More](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- arrary: `indexOf()`, `push()`, `slice()`, `map()`, `filter()`, `each()`
- [Learn More](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)
- object: `assign()`, `create()`, `keys()`, `values()`, `assign()`
- [Learn More](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
### Variables
The last piece we need to create data for our JS Machine to use.
> The `var` statement declares a variable, optionally initializing it to a value.
>[Learn More](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var)
![varibles](http://i.imgur.com/JJDi3en.gif)
### Manipulating and changing data
#### Operators, Conditionals and Loops
![](https://gamersunitedggblog.files.wordpress.com/2018/03/pc2.gif)
## Actions
Teaching our JS Machine new things.
How do we perform custom actions in JavaScript?
- we create and call functions
### Functions
> Functions are one of the fundamental building blocks in JavaScript. A function is a JavaScript procedure—a set of statements that performs a task or calculates a value. To use a function, you must define it somewhere in the scope from which you wish to call it.
> [Learn More](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions)
1. Defining a Function (creating a function)
```javascript
[keyword:function][identifier: someName][parameters:()]{
//code goes here
}
function kick(){
console.log("Kick Action")
}
```
2. Calling the function = telling the JS engine to perform the custom action `kick`
```javascript
kick();
/* OUTPUT TO CONSOLE
Kick Action
*/
```
![Kick](https://media.giphy.com/media/3ov9jERpsAGqQ8cMh2/giphy.gif)
----------------------
<a href="demo"></a>
# Demo
- https://repl.it/@ricklopez/UsedCulturedCloudcomputing
# Resources
- [Tony Alecia](https://www.youtube.com/watch?v=Bv_5Zv5c-Ts)
- [Kyle Simpson](https://github.com/getify)
- [John Resig](https://johnresig.com/)
以上是关于markdown js_the_very_basics_public.md的主要内容,如果未能解决你的问题,请参考以下文章