본문 바로가기

전체 글343

[Rust] Function Rust's function is the same as other languages. The main() function is the most important function and it is the entry point of programs. Define Function fn keyword allows us to declare new functions. The naming convention of the function is snake case. fn main() { println!("main() function"); test(); } fn test() { println!("test() function"); } Parameters and Return Values We can define functio.. 2022. 8. 1.
[Rust] Control Flow If you have studied other languages, you can use it almost similarly. if Expression if expression allows us to branch code depending on conditions. fn main() { let number = 3; if number == 1 { println!("Number is 1"); } else if number == 2 { println!("Number is 2"); } else { println!("Large number!"); } } The condition in if expression must be a boolean type. In other words, Rust doesn't have tr.. 2022. 7. 31.
[Rust] Operator Below are the operators in Rust. Macro Explanation Usage ! Macro expansion ident!(...) ident!{…} ident![…] == Equality comparison expr == expr ≠ Nonequality comparison var ≠ expr Greater than comparison expr > expr ≥ Greater than or equal to comparison expr ≥ expr + Arithmetic addition expr + expr += Arithmetic addition and assignment var += expr - Arithmetic negation -expr - Arithmetic subtract.. 2022. 7. 30.
[Rust] Data Type Rust is a statically typed language, meaning it must know all variables' types at compile time. Every value in Rust is of a particular data type. Rust's data types can be roughly divided into two types, which are scalar and compound. If we omit explicit data types, the compiler infers it. Scalar Type A scalar type represents a single value. Integer Type There are signed integers and unsigned int.. 2022. 7. 30.
[Rust] Variables Rust's naming convention for variables is the same as other languages. It can have the alphabet, number, and underscore, and can't start with numbers. Immutable Variable Variables are declared using the let keyword and by default it is immutable. fn main() { let x = 1; x = 2; // error[E0384]: cannot assign twice to immutable variable } Mutable Variable Using the mut keyword to make variables mut.. 2022. 7. 28.
[Rust] Getting Started Rust with VS Code Rust is a language empowering everyone to build reliable and efficient software. Installation You can install Rust through curl. $ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh Please find it in the below link. https://www.rust-lang.org/tools/install Check the version to verify whether it is properly installed or not. $ rustc --version My version was rustc 1.62.1. cargo cargo is.. 2022. 7. 26.
[JavaScript] Map Object The Map object holds key-value pairs and remembers the original insertion order of the keys. Any value may be used as either a key or a value. A key should be unique. Create a Map Object The Map() constructor creates a new Map object. const map = new Map(); // Map(0) {} const map = new Map([ ['key1', 'value1'], ['key2', 'value2'] ]); // Map(2) {'key1' => 'value1', 'key2' => 'value2'} const map =.. 2022. 7. 14.
[JavaScript] Set Object The Set object lets you store unique values of any type, whether primitive values or object references. Create an Set Object The Set constructor creates a Set object. const set = new Set(); // Set(0) {} const set = new Set([1, 2, 3, 3]); // Set(3) {1, 2, 3} const set = new Set('Hello'); // Set(4) {'H', 'e', 'l', 'o'} Set objects consider that all NaNs are the same. console.log(NaN === NaN); // f.. 2022. 7. 13.
[JavaScript] String Object The String object is used to represent and manipulate a sequence of characters. Create a String The string constructor creates an instance by type coercion an argument into a string. const strObj = new String(); const strObj = new String('HoYa'); const strObj = new String(123); // '123' If we don't use the new operator, it is converted to a string and returned. String(1); // '1' String(NaN); // .. 2022. 7. 10.