





























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
A brief overview of Javascript, including how computers interpret code, data types, text editors, variables, arrays, objects, boolean algebra, iteration, and functions. The lecture goals are to understand how a computer interprets code, have a vocabulary to talk about programming, write and understand some JavaScript code, and know what to ask and where to look when stuck. useful as study notes, lecture notes, and summaries for university and high school students studying computer science or programming.
Typology: Lecture notes
1 / 37
This page cannot be seen from the preview
Don't miss anything!
● Understand (at a high level) how a computer interprets code.
● Have a vocabulary to talk about programming.
● An ability to write and understand some JavaScript code.
● Understand what to ask and where to look when you get stuck.
Taken from: http://computer.howstuffworks.com/computer-memory1.htm
● The fundamental language of computers is binary.
010100101 = 2 7 + 2 5 + 2 2 + 2 0 = 165
● A bit is one binary digit. ● A byte is 8 bits. ● A megabyte is (roughly) 1 million bytes. ● A gigabyte is (roughly) 1 billion bytes.
● Programs are written in a human-readable format.
● We need a mechanism to translate human- readable code into machine-readable numbers.
● Compilers provide one way to translate high-level (human-readable) code into low- level (machine-readable) code.
section global _start, .text write write : mov al , 1 ; write syscall syscall ret _start: mov rax , 0x0a68732f6e69622f push xor raxrax , rax mov mov rsirdi ,, 1 rsp mov call rdxwrite , 8 exit: ; just exit not a function xor rax , rax mov syscall rax , 60
function my_func(foo, bar) { var bud = foo; if (bar && typeof bar === "string") { bar = bar + "blah"; } return bud + bar; };
JavaScript Code Machine Code (for an Intel CPU) Compilation
● Can't use Microsoft Word to write code.
● Programmers use WYSIWYG editors, which allow them to see exactly what is inside a file.
● W hat Y ou S ee I s W hat Y ou G et (WYSIWYG)
e.g. Notepad (Windows), TextEdit (OSX), etc. NOTE: make sure files are being saved as plaintext! You can look in Preferences for this option.
● All languages have a grammar that defines valid syntax.
● Programs can be thought of as a collection of statements made up of expressions written using the language's syntax.
● Each statement is executed in sequential order.
● Consoles give us a way to execute individual statements of JavaScript.
● A good way to make sure you understand what your code is doing.
● In Chrome: View->Developer->JavaScript Console
● Other browsers: http://webmasters.stackexchange. com/questions/8525/how-to-open-the- javascript-console-in-different-browsers
● The next statement isn't executed until the current statement is finished (statment 3 didn't execute until we closed the alert window).
● This is called synchronous execution (as opposed to asynchronous , which is an important technique in web programming).
Variables have specific data types.
// number var x = 1; var y = 2; var z = 0; // object var point = {x: x, y: y, z: z}; // array var point_array = [point, point];
● Data types specify what operations are valid, and what those operations do.
var x = 1, y = 2; x + y; // 3 var name = "sam"; x + name; // "1sam" var foo = []; foo.length; // 0 var bar = {}; bar.length; // undefined
● Arrays are lists of data. ● In JavaScript, these lists can have any kind of data.
var my_empty_array = [];
var my_array = [1, 2, 3, 4];
var my_mixed_array = ['foo', 1, []];
● Arrays have special methods to help you manipulate them.
var my_array = [];
my_array.push(1); // [ 1 ]
my_array.push(2, 3); // [ 1, 2, 3]
// slice( index , delete_count );
my_array.splice(1, 1); // [ ????? ]