JavaScript Basics: Difference between revisions
Moved page from wikipedia:en:Draft:JavaScript Basics ([[Edithistory:|history]]) |
m replace single = by == |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
{{AFC comment|1=[[WP:NOTHOWTO]] [[User:Mcmatter|McMatter]] <sup>([[User talk:Mcmatter|talk]])</sup>/<sub>([[Special:Contributions/Mcmatter|contrib]])</sub> 02:10, 29 August 2022 (UTC)}} | {{AFC comment|1=[[WP:NOTHOWTO]] [[User:Mcmatter|McMatter]] <sup>([[User talk:Mcmatter|talk]])</sup>/<sub>([[Special:Contributions/Mcmatter|contrib]])</sub> 02:10, 29 August 2022 (UTC)}} | ||
| Line 9: | Line 7: | ||
{{AfC topic|stem}} | {{AfC topic|stem}} | ||
= JavaScript Basics = | == JavaScript Basics == | ||
=== Variables === | === Variables === | ||
Variables | Variables<ref>{{Citation |title=Variable (computer science) |date=2022-08-19 |url=https://en.wikipedia.org/w/index.php?title=Variable_(computer_science)&oldid=1105315140 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> are data stored as a value in a named space. Variables can be used as a mathematical constant,<ref>{{Citation |title=Constant (mathematics) |date=2022-06-02 |url=https://en.wikipedia.org/w/index.php?title=Constant_(mathematics)&oldid=1091159181 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> to use in math commands to generate a user output,<ref name=":0">{{Citation |title=Input/output |date=2022-08-28 |url=https://en.wikipedia.org/w/index.php?title=Input/output&oldid=1107158004 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> such as e,<ref>{{Citation |title=e (mathematical constant) |date=2022-08-26 |url=https://en.wikipedia.org/w/index.php?title=E_(mathematical_constant)&oldid=1106854025 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> which has a value of 2.718281828459045. To declare a new constant, type the keyword "const",<ref>{{Citation |title=const (computer programming) |date=2022-08-20 |url=https://en.wikipedia.org/w/index.php?title=Const_(computer_programming)&oldid=1105407141 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> and add the [[JavaScript syntax#Declaration and assignment|assignment declaration]]. Add the value to declare the constant. Note that constants cannot be changed afterward, which should be self-explanatory. Normal variables work the same way, and can be changed accordingly depending on user input. Variables can also hold strings,<ref>{{Citation |title=String (computer science) |date=2022-08-01 |url=https://en.wikipedia.org/w/index.php?title=String_(computer_science)&oldid=1101756832 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> which is useful for input such as authorization<ref>{{Citation |title=Authorization |date=2022-08-18 |url=https://en.wikipedia.org/w/index.php?title=Authorization&oldid=1105166484 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> or for a search engine.<ref>{{Citation |title=Search engine |date=2022-08-28 |url=https://en.wikipedia.org/w/index.php?title=Search_engine&oldid=1107150189 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> Variables can also identify as undefined<ref>{{Citation |title=Undefined value |date=2021-12-09 |url=https://en.wikipedia.org/w/index.php?title=Undefined_value&oldid=1059485044 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> or null.<ref>{{Citation |title=Null character |date=2022-08-10 |url=https://en.wikipedia.org/w/index.php?title=Null_character&oldid=1103680343 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> | ||
=== Functions === | === Functions === | ||
| Line 18: | Line 16: | ||
=== Event Keywords === | === Event Keywords === | ||
[[Event (computing)|Events]] is a trigger usually initiated by user input<ref name=":0" /> | [[Event (computing)|Events]] is a trigger usually initiated by user input,<ref name=":0" /> which allows certain blocks of code to execute. Here's a [[HTML attribute#Event attributes|complete list]]. | ||
=== WebSockets and User Connections === | === WebSockets and User Connections === | ||
User connections include social networking<ref>{{Citation |title=Social networking service |date=2022-08-22 |url=https://en.wikipedia.org/w/index.php?title=Social_networking_service&oldid=1105837230 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> | User connections include social networking,<ref>{{Citation |title=Social networking service |date=2022-08-22 |url=https://en.wikipedia.org/w/index.php?title=Social_networking_service&oldid=1105837230 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> messaging between users,<ref>{{Citation |title=Message |date=2022-07-26 |url=https://en.wikipedia.org/w/index.php?title=Message&oldid=1100585875 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> or playing an online game.<ref>{{Citation |title=Multiplayer video game |date=2022-08-12 |url=https://en.wikipedia.org/w/index.php?title=Multiplayer_video_game&oldid=1104068378 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> WebSocket<ref>{{Citation |title=WebSocket |date=2022-08-06 |url=https://en.wikipedia.org/w/index.php?title=WebSocket&oldid=1102718692 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> is a protocol used for seamless and fast communication listening on a port.<ref>{{Citation |title=Port (computer networking) |date=2022-08-04 |url=https://en.wikipedia.org/w/index.php?title=Port_(computer_networking)&oldid=1102379124 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> Encoded messages are sent over this line, usually in a JSON format.<ref>{{Citation |title=JSON |date=2022-08-25 |url=https://en.wikipedia.org/w/index.php?title=JSON&oldid=1106610160 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> WebSocket is supported by [[Google Chrome]], [[Firefox]], [[Safari (web browser)|Safari]], [[Microsoft Edge]], [[Internet Explorer]], and [[Opera (web browser)|Opera]]. This server can be utilized with a variable. Declare a variable and set the value to "new WebSocket()". Inside of the parentheses put the [[URL|URL (Uniform Resource Locator)]] of your WebSocket connection. Create custom functions for this to create a [[Instant messaging|chat application]] or another idea. | ||
=== Recap === | === Recap === | ||
Latest revision as of 18:43, 14 January 2025
JavaScript Basics
Variables
Variables[1] are data stored as a value in a named space. Variables can be used as a mathematical constant,[2] to use in math commands to generate a user output,[3] such as e,[4] which has a value of 2.718281828459045. To declare a new constant, type the keyword "const",[5] and add the assignment declaration. Add the value to declare the constant. Note that constants cannot be changed afterward, which should be self-explanatory. Normal variables work the same way, and can be changed accordingly depending on user input. Variables can also hold strings,[6] which is useful for input such as authorization[7] or for a search engine.[8] Variables can also identify as undefined[9] or null.[10]
Functions
Functions[11] are a keyword used in object-oriented programming. These are used to run code multiple times, for example, a login button. They can setup the procedure and insert it inside of a function named loginProcedure. Using the Document Object Model, they can have the function execute when an HTML element is clicked.
Event Keywords
Events is a trigger usually initiated by user input,[3] which allows certain blocks of code to execute. Here's a complete list.
WebSockets and User Connections
User connections include social networking,[12] messaging between users,[13] or playing an online game.[14] WebSocket[15] is a protocol used for seamless and fast communication listening on a port.[16] Encoded messages are sent over this line, usually in a JSON format.[17] WebSocket is supported by Google Chrome, Firefox, Safari, Microsoft Edge, Internet Explorer, and Opera. This server can be utilized with a variable. Declare a variable and set the value to "new WebSocket()". Inside of the parentheses put the URL (Uniform Resource Locator) of your WebSocket connection. Create custom functions for this to create a chat application or another idea.
Recap
View the references for more info on this topic. Event keywords, WebSockets, Functions, and Variables were all listed in this page.
// Variables
var variable = 1;
const constant = 2;
// Better to use let keyword
let username = user;
// Functions
function myFunction() {
console.log("Hello World!")
}
// Execute this function
myFunction()
// WebSockets
let socket = new WebSocket("server-url")
/* Add your custom WebSocket
functionality here! */
View the references for more info.
References
- ↑ "Variable (computer science)", Wikipedia, 2022-08-19, retrieved 2022-08-29
- ↑ "Constant (mathematics)", Wikipedia, 2022-06-02, retrieved 2022-08-29
- ↑ 3.0 3.1 "Input/output", Wikipedia, 2022-08-28, retrieved 2022-08-29
- ↑ "e (mathematical constant)", Wikipedia, 2022-08-26, retrieved 2022-08-29
- ↑ "const (computer programming)", Wikipedia, 2022-08-20, retrieved 2022-08-29
- ↑ "String (computer science)", Wikipedia, 2022-08-01, retrieved 2022-08-29
- ↑ "Authorization", Wikipedia, 2022-08-18, retrieved 2022-08-29
- ↑ "Search engine", Wikipedia, 2022-08-28, retrieved 2022-08-29
- ↑ "Undefined value", Wikipedia, 2021-12-09, retrieved 2022-08-29
- ↑ "Null character", Wikipedia, 2022-08-10, retrieved 2022-08-29
- ↑ "Function object", Wikipedia, 2022-04-22, retrieved 2022-08-29
- ↑ "Social networking service", Wikipedia, 2022-08-22, retrieved 2022-08-29
- ↑ "Message", Wikipedia, 2022-07-26, retrieved 2022-08-29
- ↑ "Multiplayer video game", Wikipedia, 2022-08-12, retrieved 2022-08-29
- ↑ "WebSocket", Wikipedia, 2022-08-06, retrieved 2022-08-29
- ↑ "Port (computer networking)", Wikipedia, 2022-08-04, retrieved 2022-08-29
- ↑ "JSON", Wikipedia, 2022-08-25, retrieved 2022-08-29
This article "JavaScript Basics" is from Wikipedia. The list of its authors can be seen in its historical and/or the page Edithistory:JavaScript Basics. Articles copied from Draft Namespace on Wikipedia could be seen on the Draft Namespace of Wikipedia and not main one.
